FAQ Database Discussion Community


Select specific element type with specific ID in jQuery

javascript,jquery,jquery-selectors
I want to find any canvas elements with the id whatever using jQuery. I thought I could do $('canvas #whatever') but that doesn't return anything when I have a canvas with that id on the page.

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

Click handler for element with highest z-index only

javascript,jquery,html,css,jquery-selectors
In a page I'm creating there are some WebGrid components serving as master grids, and on clicking a row, a details area is shown. Now every row shall also have a delete button, so that clicking this button, the row is deleted. Now because I have a click handler for...

How do you select in-line text with Jquery?

javascript,jquery,jquery-selectors
How can I select the text infront of the unordered list below? <li class="foo"> How can I remove this text? <ul class="bar"> <li><a href="#">Link</a></li> </ul> </li> I tried doing something like this: $('ul.bar').previousSibling().remove(); But I think that would only work with another element, and I'm not entirely sure how to...

Is there any meaning to 'first' pseudoclass?

jquery,jquery-selectors
I found this code: $("#some_list li a:first").click(); And I can't find any source about 'first' pseudoclass. Have anyone seen something like that ? Does it mean that first element on list is clicked ?...

Get the next div and check that div for a class exists in it's childs

jquery,html,jquery-selectors
How do I determinate if one of the buttons have the class "selected"? <a id="foo">Foo</a> <div id="div"> <input type="button" /> <input type="button" class="selected" /> <input type="button" /> </div> I wrap foo into a jQuery object. Call next() to get to the div. How do I do the rest? function fooClickHandler(foo)...

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

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

Find all input with specific keyword [duplicate]

jquery,jquery-selectors
This question already has an answer here: jQuery selector for a checkbox that contains certain text in its name attribute 3 answers I'd like to find all the inputs that have at the end of their names the keyword [0]. I guess I have to use the following method:...

Using the this keyword with jQuery selectors

jquery,jquery-selectors,this
Can someone please help me with the syntax of using the jQuery this keyword? Here is my code that works: var obj = jQuery.parseJSON(data); $('.example_infobox1').addClass(obj.gridlayout); $('.example_infobox1 .info-box').addClass(obj.boxcolor); $('.example_infobox1 .info-box-icon').addClass(obj.iconcolor); $('.example_infobox1 i').addClass(obj.icon); $('.example_infobox1 .info-box-text').html(obj.text); $('.example_infobox1 .info-box-number').html(obj.number); Here is the code that I am working on: var obj = jQuery.parseJSON(data);...

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

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

CSS or jQuery selctor? [closed]

jquery,html,css,jquery-selectors,css-selectors
Let's say there is the following HTML: <div id="test"> <span class="testSpan"></span> </div> There are two ways of selecting the span inside the #test div (I know I can select the span directly but this is not the point of the question): $('#test > .testSpan'); and $('#test').find('.testSpan'); Which of these ways...

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

Jquery.on('click') does not work on “class selector”

jquery,jquery-selectors
The following code http://jsfiddle.net/HCUYW/100/ does not emit click event. $(".todoitem").on('click', function() { alert('Item selectedd'); }); The workaround is to use the click method directly as $(".todoitem").click(...). How to make the .on('click',...) work on class selector ?...

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

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

How to find an element by data attribute with find() function?

javascript,jquery,jquery-selectors
I add a data attribute to an element via jquery data() function. I want to use find() function to get the element. But obviously, it does not work. What I want to do is caching the element's parent element and do a lot of things. Like this: var $parent =...

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

jQuery selector based on not having class inside

javascript,jquery,jquery-selectors
I need to select an element based on what is not inside it's element. <div class="person"> <div class="name">Jason</div> </div> <div class="person"> </div> What do I need to do to select the second div with the person class. I know there are has and not properties, do I need to combine...

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

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

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

`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' />...

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

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 set array value into textfield using selectize.js

javascript,jquery,jquery-selectors,selectize.js
Hello I have a problem regarding selectize. I tried and test this code to ensure that I get a list of email coming from the database. for(var i = 0; i < e.email.length; i++){ console.log(e.email[i]); var list = e.email[i]; } The results are fine and I get what I want....

Stored selector doesn't work correctly with each()

jquery,jquery-selectors
Below is a recreation of the problem I'm having. I stored $('.box') into the $box variable. In my actual code, I'm using $box in many places to do things and it works fine, except in the portion of code below, where I tried to use loop through the many $box's...

Not able to access click event with jQuery selector

javascript,jquery,html,jquery-selectors
I am having a hard time accessing a click even with my jQuery selector. Here is my HTML: <li class="handle-bars"> <span class="fa fa-bars pull-right text-primary m-t-10"></span> <span class="fa fa-cogs pull-right text-primary m-t-10" id="trigger-modal-editor" style="cursor:pointer" data-target="#modalSlideLeft" data-toggle="modal"> </span> </li> Here is my jQuery selector: <script> $(document).ready(function() { $('#trigger-modal-editor').click(function() { alert('Hello'); });...

Can't select span inside div (jquery) [closed]

jquery,html,jquery-selectors
I can't seem to select the span inside the image below with the class 'star-rating-control. I'm trying to move it to one of the labels above (which I can select) Can anyone help? I've tried the following: var test = $("span.star-rating-control"); var test = $("div.write-review form#reviews span.star-rating-control"); If any other...

Jquery: How to select a specific previous id dynamically?

jquery,jquery-selectors
I'm trying to add a comment box like you could open in Facebook when you click on "comment". So I want to select the most previous id containing "users_log_id" of the current "comment" link I'm clicking on. Note: After "users_log_id" is always the id of the current id like this:...

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

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

Syntax error with jquery selecting table row with a specific attribute

javascript,jquery,jquery-selectors
I am trying to pull the data out from a table row so that it can be updated, but I am really confused as to why it is not happening. Below is a snippet of generated HTML. The record ID is held in the first data element as the value...

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

Assigning onclick via jQuery selector

javascript,jquery,jquery-selectors
I am trying to assign an anchor's onclick via javascript - see jsfiddle below: <a id="link_a" class="linka" href="http://www.google.com">link 1</a> var lnkA=$('.linka'); lnkA.onclick=function(){alert(this.innerHTML);}; fiddle: https://jsfiddle.net/andrewtr/tkfvyr7o/ Code: However, it doesn't seem to work. What am I doing wrong? Thanks!...

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

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(' +...

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

Jquery Change CSS of variable div

jquery,jquery-selectors
I have a table with a bunch of td with the classes markTD and they each have a different integer for the attribute value. I would like to click the button called mark and change the color of just 1 of the td. $('#mark').click(function(){ var h2 = parseInt($('#h2').attr('value'), 10); //h2...

Select a specific number of items of a specific type which are brothers with jQuery

jquery,jquery-selectors
I wish to add a class to pictures in a p only if they're strictly 2 pics in the p (not an alone img or more than 2), with a jQuery selector. <div class="wysiwyg"> <p> <img class="addHere"/> <img class="addHere"/> </p> <p> <img/> </p> </div> For now, I have something like...

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

Union between two jquery selectors

jquery,jquery-selectors,selector
This is my case: var elems = form.find(':input'); var clEditors = form.find('.cleditor').parent(); elems.css('border', '2px'); clEditors.css('border', '2px'); Is there anyway I could prevent the duplication and do something like this: var elems = form.find(':input').union(form.find('.cleditor').parent()); elems.css('border', '2px'); I tried using a multi selector with the :parent selector and it didn't work: var...

Select all Children except first N - CSS Selector

jquery,css,jquery-selectors,css-selectors
<td> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> <p></p> </td> I want to get all ps except the first 3. I am doing it like so td p:not(:nth-child(1),:nth-child(2),:nth-child(3)) But what if I want all ps except first 20? Will I have to write manually like I did above?...

jQuery selector next child of nested elements

javascript,jquery,html,twitter-bootstrap,jquery-selectors
How to select the next input within nested elements? For example: when currently selecting 1a, pressing the down arrow key should select 2x, and down again should select 3x, and so on until 6x. In the other case, if currently selecting 1a, press the right arrow key should select 1b....

Add class to nth of an element found on full page instead within a parent

jquery,jquery-selectors,element,addclass
I'm trying to add classes to the "nth" of a particular element - regardless of where it falls on the page. A simplified version of my html is: <div class="row"> <div class="col-sm-12"><section class="subsection"></section></div> <div class="col-sm-12"><section class="subsection"></section></div> </div> <div class=“row”> <div class="col-sm-12"><section class="subsection"></section></div> <div class="col-sm-12"><section...

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

Strange behaviour with jQuery pseudo selector :visible

javascript,jquery,jquery-selectors
I have a query that looked like this: $("div.modal:visible select#DTE_Field_calculator\\.type") which would attempt, in theory, to find that <select> tag inside of the currently visible div.modal element. Unfortunately, it would return nothing at all, despite the DOM looking exactly as you would expect (<div class="modal">...<select id="DTE_Field_calculator.type">...) If I removed the...

jQuery button to show/hide multiple divs with same id

jquery,jquery-selectors,click,element,slidetoggle
I have many products being populated dynamically, all with same id and class names. I want each "Buy Now" button to have its own div that toggles with click of button. I do have the ability to assign an incrementing number index to the ids and classes, however, if there's...

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

jQuery selector