Skip to main content

Questions tagged [jquery-selectors]

Selectors can be used in jQuery to match a set of elements in a document. Most CSS selectors are implemented, as well as a set of custom ones.

jquery-selectors
3068 votes
39 answers
2.5m views

How can I know which radio button is selected via jQuery?

I have two radio buttons and want to post the value of the selected one. How can I get the value with jQuery? I can get all of them like this: $("form :radio") How do I know which one is selected?
juan's user avatar
  • 81.3k
2533 votes
35 answers
2.4m views

Get selected text from a drop-down list (select box) using jQuery

How can I get the selected text (not the selected value) from a drop-down list in jQuery?
haddar's user avatar
  • 25.5k
2414 votes
19 answers
2.0m views

How to get the children of the $(this) selector?

I have a layout similar to this: <div id="..."><img src="..."></div> and would like to use a jQuery selector to select the child img inside the div on click. To get the div, I've ...
Alex's user avatar
  • 26.6k
2284 votes
14 answers
1.1m views

How can I select an element with multiple classes in jQuery?

I want to select all the elements that have the two classes a and b. <element class="a b"> So, only the elements that have both classes. When I use $(".a, .b") it gives me the union, but I ...
Mladen's user avatar
  • 25.7k
1683 votes
20 answers
2.7m views

How can I get the ID of an element using jQuery?

<div id="test"></div> <script> $(document).ready(function() { alert($('#test').id); }); </script> Why doesn't the above work, and how should I do this?
fearofawhackplanet's user avatar
1544 votes
15 answers
2.3m views

How can I select an element by name with jQuery?

I have a table column I’m trying to expand and hide. jQuery seems to hide the <td> elements when I select it by class but not by the element’s name. For example: $(".bold").hide(); // ...
T.T.T.'s user avatar
  • 34.2k
1285 votes
23 answers
1.1m views

jQuery get specific option tag text

Suppose I have a drop-down list like: <select id='list'> <option value='1'>Option A</option> <option value='2'>Option B</option> <option value='3'>...
Paolo Bergantino's user avatar
1239 votes
29 answers
3.4m views

Set select option 'selected', by value

I have a select field with some options in it. Now I need to select one of those options with jQuery. But how can I do that when I only know the value of the option that must be selected? I have the ...
w00's user avatar
  • 26.6k
1173 votes
9 answers
1.7m views

jQuery how to find an element based on a data-attribute value?

I've got the following scenario: var el = 'li'; and there are 5 <li>'s on the page each with a data-slide=number attribute (number being 1,2,3,4,5 respectively). I now need to find the ...
Jannis's user avatar
  • 17.3k
1150 votes
28 answers
901k views

Selecting and manipulating CSS pseudo-elements such as ::before and ::after using javascript (or jQuery)

Is there any way to select/manipulate CSS pseudo-elements such as ::before and ::after (and the old version with one semi-colon) using jQuery? For example, my stylesheet has the following rule: .span::...
JBradwell's user avatar
  • 11.6k
1120 votes
13 answers
2.8m views

Get the value in an input text box

What are the ways to get and render an input value using jQuery? Here is one: $(document).ready(function() { $("#txt_name").keyup(function() { alert($(this).val()); }); }) <...
Bharanikumar's user avatar
  • 25.6k
771 votes
15 answers
1.1m views

jQuery to loop through elements with the same class

I have a load of divs with the class testimonial and I want to use jquery to loop through them to check for each div if a specific condition is true. If it is true, it should perform an action. Does ...
geoffs3310's user avatar
  • 13.9k
735 votes
6 answers
552k views

Wildcards in jQuery selectors

I'm trying to use a wildcard to get the id of all the elements whose id begin with "jander". I tried $('#jander*'), $('#jander%') but it doesn't work.. I know I can use classes of the elements to ...
tirenweb's user avatar
  • 31.4k
730 votes
4 answers
807k views

jQuery selectors on custom data attributes using HTML5

I would like to know what selectors are available for these data attributes that come with HTML5. Taking this piece of HTML as an example: <ul data-group="Companies"> <li data-company="...
Jose3d's user avatar
  • 9,237
690 votes
13 answers
745k views

document.getElementById vs jQuery $()

Is this: var contents = document.getElementById('contents'); The same as this: var contents = $('#contents'); Given that jQuery is loaded?
Phillip Senn's user avatar
  • 47.3k

15 30 50 per page
1
2 3 4 5
601