jQuery selectors are one of the most important parts of the jQuery library.
jQuery selectors allow you to select and manipulate HTML elements as a group or as a single element.
jQuery selectors are required at every step while using jQuery. Selectors allow you to get the exact element/attribute you want from your HTML document.
jQuery supports the existing CSS Selectors, and in addition, it has some own custom selectors.
All type of selectors in jQuery, start with the dollar sign and
parentheses: $().
$("*") selects all elements.
$("p") selects all <p> elements.
$("p.intro") selects all <p> elements with class="intro".
$("p#intro") selects the first <p> elements with id="intro".
$(":animated") selects all elements that are currently animated.
$(":button") selects all <button> elements and <input> elements of type="button".
$(":even") selects even elements.
$(":odd") selects odd elements.
| Syntax | Description |
|---|---|
| $(this) | Selects the current HTML element |
| $("p#intro:first") | Selects the first <p> element with id="intro" |
| $(".intro") | Selects all elements with class="intro" |
| $("#intro") | Selects the first element with id="intro" |
| $("ul li:first") | Selects the first <li> element of the first <ul> |
| $("ul li:first-child") | Selects the first <li> element of every <ul> |
| $("[href]") | Selects all elements with an href attribute |
| $("[href$='.jpg']") | Selects all elements with an href attribute that ends with ".jpg" |
| $("[href='#']") | Selects all elements with an href value equal to "#" |
| $("[href!='#']") | Selects all elements with an href value NOT equal to "#" |
| $("div#intro .head") | Selects all elements with class="head" inside a <div> element with id="intro" |
Use our jQuery Selector Tester to experiment with the different selectors.
For a full reference please go to our jQuery Selectors Reference
| WEB HOSTING |
|---|
| Best Web Hosting |
| PHP MySQL Hosting |
| Best Hosting Coupons |
| UK Reseller Hosting |
| Cloud Hosting |
| Top Web Hosting |
| $3.98 Unlimited Hosting |
| Premium Website Design |
| WEB BUILDING |
|---|
| XML Editor - Free Trial! |
| FREE Website BUILDER |
| Best Website Templates Top CSS Templates |
| CREATE HTML Websites |
| EASY WEBSITE BUILDER |
| W3SCHOOLS EXAMS |
|---|
|
Get Certified in: HTML, CSS, JavaScript, XML, PHP, and ASP |
| W3SCHOOLS BOOKS |
|---|
|
New Books: HTML, CSS JavaScript, and Ajax |
| STATISTICS |
|---|
|
Browser Statistics Browser OS Browser Display |
| SHARE THIS PAGE |
|---|