FAQ Database Discussion Community


JQuery .find() failing on an .ajax() result

jquery,html,ajax,google-chrome-extension,jquery-selectors
I'm working on a Chrome extension which, under certain conditions, performs a $.ajax() request and then uses information of specific elements in the returned HTML. For now, I'm simply trying to have it access the specific element and log it to the console to ensure it works correctly. To start,...

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...

Get just class names from string selector, jQuery way?

jquery,jquery-selectors
Suppose I have string selector such as: input.js-pretty-select[type="radio"].selected How can I get just all class names (js-pretty-select and selected) from this string, possibly using some jQuery core function? I thought about some regex at first, but then I realized that jQuery might have that already implemented somewhere in it's code,...

Finding the name of method in jquery

jquery,jquery-selectors
I am trying to find the method names in my html code. So I will find the method name in 'onclick' attribute and then make operations. This is current code: <div class="button" style="width: 60px; float: right;" onclick="closeModalDialog('dialogAttachmentModal');">BLABLA</div> I want to write jquery like this: $('closeModalDialog').attr('id','btnCloseModal'); And I want to show...

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...

`div input[type='checkbox']:lt(2)` only selecting first row

jquery,html,jquery-selectors
I want to cause an alert when the user clicks on either of the first two <input>s in each row, but my current code is only working for the first row. How can I fix my selector to work for the rest of the rows? HTML: <div> <input type='checkbox' />...

jQuery :empty not working with input

javascript,jquery,jquery-selectors
I am having a problem in using jQuery's :empty pseudo selector. Basically, it isn't working on inputs the way I think it should. Given this html, I'm trying to get a count of all the inputs which don't have values without a loop. <div id="sampleDiv"> <label>My first Input:</label> <input name="test"...

How to select a single cloned element?

jquery,jquery-selectors,clone
I am dynamically adding a div to my webpage when ever I click a button. I am doing this by cloning an original div and appending the clone. I have the above figured out. However, within the cloned div there is a text input. I want to make sure the...

action on parent's sibling in jQuery

javascript,jquery,jquery-selectors
Here's my html code: <div class="btn-group js_publish_management> <button class="btn btn-danger js_publish_btn">Not Published</button> <button class="btn btn-success js_publish_btn">Published</button> <button type="button" t-attf-class="btn btn-default dropdown-toggle" data-toggle="dropdown"> <span class="caret"></span> </button> <ul class="dropdown-menu" role="menu"> <li> <a href="#" class="js_publish_btn"> <span...

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 =...

How to trigger neighbour element to “this” object in jquery

jquery,html,css,jquery-selectors
I have 1 button - <a> link and list - ul. I need to show/hide list when I click on button. Here is the code: <div class="wide-tile" id="tile-1"> <div class="size-set"> <a href="#" class="toggle-btn"> > </a> <ul class="size-list"> <li>1x1</li> <li>1x2</li> <li>2x1</li> <li>2x2</li> </ul> </div> <a href="details.html" class="wide-tile-link"> <span class="title">About us</span> </a>...

Why jquery nth child give inconsistent result when apply to ul and li

jquery,jquery-selectors
I have a container with a group of uls, of each have 4 lis. I created the first ul then copy the rest by Javascript. When I call to find nth-child of all uls, eg $("ul:nth-child(1)"), it return nothing, the first ul item appear with $("ul:nth-child(2)") (n is starting from...

jQuery: How to combine two lines of code (with same target)

jquery,jquery-selectors
I am new to jQuery and am trying to combine the following two lines of code as they both target the same div ( $(this).closest('div.col-9').nextAll('div.hiddenDiv') ) and I have other, similar scenarios where this would reduce code as well: $(this).closest('div.col-9').nextAll('div.hiddenDiv').find('input, select, textarea').removeProp('checked').removeProp('selected').not(':button, :checkbox, :hidden, :radio, :reset, :submit').val(''); $(this).closest('div.col-9').nextAll('div.hiddenDiv').hide(); It works...

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 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...

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' ) {...

what is differences between $('element , #id') and $('element', '#id') in jquery

jquery,jquery-selectors
I know $('element, #id') selects all elements & #id. But what does do $('element', '#id') !? I only know they aren't similar. So what's difference?

How can multiple variables be used to create multiple jquery selectors?

javascript,jquery,variables,jquery-selectors,addclass
When I convert multiple variables into multiple selectors the below code fails to execute. DEMO HERE $('.Btn').on('click', function () { var outer = $(this).data('test'); var inner = $(outer).children('.Inner'); $(outer + ',' + inner).addClass('Success'); }); In the code above: This is successful $(outer).addClass('Success'); This is successful $(inner).addClass('Success'); This is not $(outer...

Jquery selector not working with dynamic .get loaded content

jquery,html,jquery-selectors,selector
I have a page that dynamically loads content with a .get request from clicking a button. The HTML page that loads I can not get any jquery selector to target anything on that page. I tried putting the script for the alert on the page that gets loaded as well...

How to extend a jQuery selector that is stored in a variable?

jquery,performance,jquery-selectors
I have a jQuery selector stored in a variable, like so: var myVariable = $( ".js-selector" ); I'm wondering if and how I can use this variable to select children of this element, instead of writing: $( ".js-selector .some-child" ); How do I do this? I'm also wondering if I...

jQuery with the plus sign

javascript,jquery,html,jquery-selectors
I wonder why jQuery doesn't allow "+" sign. Here is an example of how it works with "1" and "3" but not with "2+". Just mouse-over the text above every div. <div id="div-2+"></div> JSFiddle $('a.hover').mouseover(function() { dataI = $(this).data('i'); $('div#div-' + dataI).addClass('h'); }); $('a.hover').mouseout(function() { dataI = $(this).data('i'); $('div#div-' +...

jquery selector: child elements of the same class inside divs of different classes

jquery,html,css,jquery-selectors
There are two divs with classes ".div1" and ".div2". Each of them contains the same code - the same elements with the same class names. If I need to set/get a value of an element inside one of the divs, how do I refer to those elements? I try the...

jQuery selector for second column in HTML table row

javascript,jquery,html,css,jquery-selectors
The aim of my code is to add the data from the selected HTML table row to the JavaScript array, and remove it if the row is unselected. https://jsfiddle.net/nicktry/h1636ram/ I have two problems at the moment: The CSS Style is not being applied on the 1st click I can't get...

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...

change color when a country selected

javascript,jquery,css,jquery-selectors
I am trying to change color of a telephone field when a country is selected on the <select> options. For example if someone selects UK the color must change to Red. But I'm not sure what I'm doing wrong. This doesn't change at the moment. jQuery('select[name="address[_item1][country_id]"]').change(function() { if (jQuery(this).val() ==...

Hot to get the text of the selected option in jQuery?

jquery,html,jquery-selectors
td is a jQuery variable that references a table cell <td> element. This cell contains a <select> element which contains a number of <option> elements; each has a text and value. This code returns the value (not text) of the selected option. td.children().val(); I tried many ways to get the...

Find descendant elements that do not have a specific ancestor

jquery,jquery-selectors
I want to be able to select an element and find all descendant elements with a specific class but are not contained with a similar parent element. It's hard to describe: Html: <div class="js-test js-1"> <div class="b">1</div> <div class="b">1</div> <div class="d"> <div class="b">1</div> </div> <div class="js-test js-2"> <div class="b">2</div> <div...

Get group radio button selected value via jquery

javascript,jquery,html,jquery-selectors,radio-button
How can I get the selected radio button value via jQuery? I tried: var selectedPlan = $("input[name=Plan[packageId]]:checked'").val(); alert(selectedPlan); bBt didn't work. <td style="vertical-align: top;"> <input type="radio" value="1" name="Plan[packageId]"> <lable>3 Games</lable><br> <input type="radio" value="2" name="Plan[packageId]"> <lable>5 Games</lable><br> <input type="radio" value="3" name="Plan[packageId]"> <lable>10 Games</lable><br> </td>...

JQuery how to select parent but not children

jquery,jquery-selectors
Sorry for what is probably an easy question, but I haven't found a way to make this work yet. I'm new to JQuery and I've got some nested lists which I'm trying to add a click event to a parent list which will slideToggle the children lists, which I've got...

Using a jQuery Selector With a Variable

javascript,jquery,variables,jquery-selectors
Is there any way to make something like the following code? var input = ("$(\"#div .input[id='" + id + "']\")"); input.fadeIn(); Or maybe I could use something like the following? var input = ("\"#div .input[id='" + id + "']\""); $(input).fadeIn(); PS: Take my apologies as this question was cloned but...

Embedding a function inside .delay() doesn't work porperly

jquery,html,html5,css3,jquery-selectors
So I have HTML with a table and each column has button which should fade out that table and then fade in another DIV which contains info regarding about that specific column I clicked on. so the Jquery looks like this: $(document).ready(function(){ $('#motoBttn').bind('click', function(){ $('#ServicesContent').fadeOut(); $('#infoSlector').fadeIn(); $('#motoDescContent').fadeIn(); $('#goBackDiv').fadeIn() ; })...

jQuery selector