FAQ Database Discussion Community


Select word between two words

javascript,arrays,jquery-selectors
How can I create a function that selects everything between the words X and Y and pushes it to an array. By Greili - 4 Hours and 40 Minutes ago. #NsShinyGiveaway 0 comments By ToneBob - 4 Hours and 49 Minutes ago. #NsShinyGiveaway 0 comments By hela222 - 5 Hours...

Issue with jquery selectors within group & looping over elements

javascript,jquery,jquery-selectors
My issue is 2 fold. I have the following code: $photosContainer = $("#photos-fs") $photos = $photosContainer.find(".photo"); $length = $photos.length; if ($length > 1) { setTimeout(showNextPhoto, 3000); } function showNextPhoto() { //$current = $photos.eq(0); <-- this works //$next = $photos.eq(1); <-- this works $current = $photos.find(".current"); <-- this does not $next...

Is it okay to store the result of a JQuery selector in a variable?

javascript,jquery,jquery-selectors
Developers I know tend to call the same JQuery selectors over and over instead of storing the result in a variable. They are consistent with this approach. For example, they do this: var propName = $(this).attr('data-inv-name'); var propValue = $(this).attr('data-inv-value'); Instead of this: var current = $(this); var propName =...

AddClass in jQuery on runttime and select the new class

jquery,class,jquery-selectors,onclick,addclass
I'd like to add a class to a div tag in runtime (after clicking the tag) and select the div tag by the new class name afterwards. Here is my code: HTML <div class="black" id="" style=""> black </div> CSS .black{ color:black; } .green{ color:green; } jQuery should remove class "black"...

How do I get the value in this neighboring element?

jquery,jquery-selectors
I'm having trouble with the jQuery part: HTML <div> xxxxxxxxx <div> <ul> <li><button class="addnum">xxxx</button></li> </ul> </div> </div> <div class="num"> 12345 </div> Script $(".addnum").click(function() { var pur = $(this).siblings(".num").clone(); }); I'm trying to clone the value inside ".num", which is 12345. How should I select it? *edit: sorry, I didn't mention...

Remove empty

, but allow only one per group

javascript,jquery,jquery-selectors,is-empty
I was wondering how to remove empty elements, but allow only one empty element per group (next to non-empty one) ? Something like : Example HTML : <p>Hello world</p> <p><br></p> <p><br></p> <!--This will remove--> <p><br></p> <!--This will remove--> <p>Lorem ipsum dolor sit amet</p> <p><br></p> <p><br></p> <!--This will remove--> <p>Eum ne...

How to check if TD is last with class in row

javascript,jquery,jquery-selectors
I am new to jQuery and hope someone can help me with this. I have a large HTML table with dynamically added rows. The table has a standard structure (incl. thead, tbody and tfoot). Within this table there are editable TDs (which have the class "editable" and contain a contenteditable...

Is there any way to get the closest parent which have a specific class

jquery,jquery-selectors
In my application I have to get to the closest parents of the input/textarea which has the class of ('form-group'). I use the following code: $("#contactus").validate({ highlight: function (element, errorClass) { $(element).parent('.form-group').addClass('error-sign-up'); } }); For the cases of element which is input the code is fine (the direct parents of...

How do I select a class but not its inside element?

javascript,jquery,jquery-selectors,selector
Say I have <div id="mydiv"> <div class="myclass"> <span class="otherclass"></span> and many other classes... </div> </div> I want to capture the click event on .mydiv but not inside .myclass. I tried .mydiv:not(.myclass) but it doesn't seem to work. I think it's because I might be clicking on the otherclass so the...

Correct way to add variable and selectors to a not function - jquery

javascript,jquery,arrays,variables,jquery-selectors
I have checked a few answers on SO and I think my syntax is correct, but something is not working correctly. I am trying to create an array of jquery selectors mixed with variables and store them in a not() function. I have this fiddle to demonstrate. The second line...

select special selector after $(this) selector

javascript,jquery,html,jquery-selectors
for example I have this code <script> $(document).ready(function () { $('span').each(function () { $(this).html('<div></div>') ; if ( $(this).attr('id') == 'W0' ) { $( this > div ?!!! ).text('0') } if ( $(this).attr('id') == 'W1' ) { $( this > div ?!!! ).text('1') } if ( $(this).attr('id') == 'W2' ) {...

How do I get the dom element which has not rendered with javascript?

javascript,jquery,dom,jquery-selectors
I have a simple js code: <html> <head> <title>test</title> <script type="text/javascript" src="js/jquery-1.11.2.min.js"></script> <script type="text/javascript"> console.log(document.querySelector('#nav-toggle')); // this will get null console.log($('#nav-toggle')); // this will get the element </script> </head> <body> <a id="nav-toggle" href="#">link</a> <script type="text/javascript"> console.log(document.querySelector('#nav-toggle')); // this will get the...

Passing multiple jQuery objects as an array

javascript,jquery,arrays,object,jquery-selectors
I'm wondering if it's possible to do something like this in jQuery: $( [ $selector1, $selector2, document.getElemetByID( 'test' ) ] ) EDIT: I'm lazy. $selector1 and $selector2 are already jQuery objects. I am trying to avoid using $.each. Here's a more in-depth example of what I'm trying to do: var...

How to select an element by it's value in jQuery?

jquery,jquery-selectors
I have the following HTML-source <tr> <td>Peter Pan</td> <td>Nervland</td> <td> <a href="edit/id-for-peterP">edit</a> <a href="delete/id-for-peterP">delete</a> </a></td> </tr> <tr> <td>Wendy</td> <td>Nervland</td> <td> <a href="edit/id-for-wendy">edit</a> <a href="delete/id-for-wendy">delete</a> </a></td> </tr> The task is to choose the edit-link in the row that also contains a...

jQuery XOR selector

javascript,jquery,jquery-selectors,xor
From a set of divs I want to select all the divs that contain a specific attribute and then select all the divs that do not contain any of the attributes. Example: <div data-attr="1"></div> <div data-attr="2"></div> <div data-attr="3"></div> <div data-attr="4"></div> <div data-attr="5"></div> var attrList = [3,4]; // I want to...

Apply CSS Style Up to the First Period in Every Element with a Certain Class

javascript,jquery,jquery-selectors,substring
I'm trying to apply CSS styles to all of the characters up to the first period in the text of every element with a certain class. My initial attempt was to select the first 2 characters only, but that won't work if there are sub-items ( for example: "D (i)."...

jquery select class but not id

jquery,jquery-selectors,prop
This is strange for me when I choose an element by id ; jquery code does not work , but when I choose it by classname it works great ! this code : <input name='daneshjou_number' class='daneshjou_number' type='text' > this code works : <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script> <script> $(document).ready(function(){ $(".is_daneshjou").change(function(){ //alert("The text has...

Select the first-of-type div in a list that all have a data-attribute for the state it's associated with

css,jquery-selectors,css-selectors
I have a dynamically created list of elements that are job's in a particular state. There can be more then one job per state and I'm trying to select the first one of each state, but not just the first one in this huge list. For example: <section class="careers"> <div...

How is this selector working?

javascript,jquery,jquery-selectors
In the HTML I have the following element: HTML <input id="userNameTxt" type="text" class="input" value='ABC> And i am selecting it like this in jQuery: APP.js $(userNameTxt).val() What is this selector selecting? (Like when I use $('.something') -> it's selecting the Class of the element or $('#something') it's selecting the ID.) It...

jQuery/Javascript get classes of multiple elements to show an element with this class

javascript,jquery,class,if-statement,jquery-selectors
I'm struggling with a jQuery live search. First of all the live search update with the following code works. //live search function function live_search(list) { $("#search") .change( function () { //getting search value var searchtext = $(this).val(); if(searchtext) { //finding If content matches with searck keyword $matches = $(list).find('a:Contains(' +...

jQuery selector