All type of selectors available in jQuery, always start with the dollar sign and parentheses: $().
The factory function $() makes use of following three building blocks while selecting elements in a given document:
jQuery
Description
Tag Name:
Represents a tag name available in the DOM. For example $('p') selects all paragraphs in the document.
Tag ID:
Represents a tag available with the given ID in the DOM. For example $('#some-id') selects the single element in the document that has an ID of some-id.
Tag Class:
Represents a tag available with the given class in the DOM. For example $('.some-class') selects all elements in the document that have a class of some-class.
All the above items can be used either on their own or in combination with other selectors. All the jQuery selectors are based on the same principle except some tweaking.
NOTE: The factory function $() is a synonym of jQuery() function. So in case you are using any other JavaScript library where $ sign is conflicting with some thing else then you can replace $ sign by jQuery name and you can use function jQuery() instead of $().
Example:
Following is a simple example which makes use of Tag Selector. This would select all the elements with a tag name p.
JavaScript
the title
$(document).ready(function() {
var pars = $("p");
for( i=0; i
This is a paragraph.
This is second paragraph.
This is third paragraph.
The selectors are very useful and would be required at every step while using jQuery. They get the exact element that you want from your HTML document.
Following table lists down few basic selectors and explains them with examples.
Satyapriya NayakRank #47 · 31.5K reputationPosted May 9, 2012, 8:23 PM EDT
The $() factory function:
All type of selectors available in jQuery, always start with the dollar sign and parentheses: $().
The factory function $() makes use of following three building blocks while selecting elements in a given document:
All the above items can be used either on their own or in combination with other selectors. All the jQuery selectors are based on the same principle except some tweaking.
NOTE: The factory function $() is a synonym of jQuery() function. So in case you are using any other JavaScript library where $ sign is conflicting with some thing else then you can replace $ sign by jQuery name and you can use function jQuery() instead of $().
Example:
Following is a simple example which makes use of Tag Selector. This would select all the elements with a tag name p.
the title $(document).ready(function() { var pars = $("p"); for( i=0; i This is a paragraph. This is second paragraph. This is third paragraph.To understand it in better way you can Try it yourself.
How to use Selectors?
The selectors are very useful and would be required at every step while using jQuery. They get the exact element that you want from your HTML document.
Following table lists down few basic selectors and explains them with examples.
Similar to above syntax and examples, following examples would give you understanding on using different type of other useful selectors:
$('*'): This selector selects all elements in the document.
$("p > *"): This selector selects all elements that are children of a paragraph element.
$("#specialID"): This selector function gets the element with id="specialID".
$(".specialClass"): This selector gets all the elements that have the class of specialClass.
$("li:not(.myclass)"): Selects all elements matched by
$("a#specialID.specialClass"): This selector matches links with an id of specialID and a class of specialClass.
$("p a.specialClass"): This selector matches links with a class of specialClass declared within
elements.
$("ul li:first"): This selector gets only the first
.
$("#container p"): Selects all elements matched by
that are descendants of an element that has an id of container.
$("li > ul"): Selects all elements matched by
that are children of an element matched by that contain an element matched by - that have an even index value.
that have an odd index value.- element.
- element.
- that are visible.
- that are hidden.
- element
- element
- element before the third one; in other words, the first two
- elements.
- after the second one.
. 
Just to say,
Know the answer? Forums 01
Arun PottiAnswers in the forums20answers02
Tahir AnsariAnswers in the forums5answers03
Kamlesh KumarAnswers in the forums5answers04
Sam HobbsAnswers in the forums4answers05
Željko PerićAnswers in the forums3answers?YouYour name goes here.Every answer: 20 SHARP.Join Full leaderboard → 2026
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
$("strong + em"): Selects all elements matched by that immediately follow a sibling element matched by .
$("p ~ ul"): Selects all elements matched by
that follow a sibling element matched by
.
$("code, em, strong"): Selects all elements matched by
or or .$("p strong, .myclass"): Selects all elements matched by that are descendants of an element matched by
as well as all elements that have a class of myclass.
$(":empty"): Selects all elements that have no children.
$("p:empty"): Selects all elements matched by
that have no children.
$("div[p]"): Selects all elements matched by
.
$("p[.myclass]"): Selects all elements matched by
that contain an element with a class of myclass.
$("a[@rel]"): Selects all elements matched by that have a rel attribute.
$("input[@name=myname]"): Selects all elements matched by that have a name value exactly equal to myname.
$("input[@name^=myname]"): Selects all elements matched by that have a name value beginning with myname.
$("a[@rel$=self]"): Selects all elements matched by
that have a class value ending with bar
$("a[@href*=domain.com]"): Selects all elements matched by that have an href value containing domain.com.
$("li:even"): Selects all elements matched by
$("tr:odd"): Selects all elements matched by
$("li:first"): Selects the first
$("li:last"): Selects the last
$("li:visible"): Selects all elements matched by
$("li:hidden"): Selects all elements matched by
$(":radio"): Selects all radio buttons in the form.
$(":checked"): Selects all checked boxex in the form.
$(":input"): Selects only form elements (input, select, textarea, button).
$(":text"): Selects only text elements (input[type=text]).
$("li:eq(2)"): Selects the third
$("li:eq(4)"): Selects the fifth
$("li:lt(2)"): Selects all elements matched by
$("p:lt(3)"): selects all elements matched by
elements before the fourth one; in other words the first three
elements.
$("li:gt(1)"): Selects all elements matched by
$("p:gt(2)"): Selects all elements matched by
after the third one.
$("div/p"): Selects all elements matched by
that are children of an element matched by
$("div//code"): Selects all elements matched by
that are descendants of an element matched by.- that are the first child of their parent.
- that are the last child of their parent.
- that contain the text second.
- element then $("p:first") would also work for
$("//p//a"): Selects all elements matched by that are descendants of an element matched by
$("li:first-child"): Selects all elements matched by
$("li:last-child"): Selects all elements matched by
$(":parent"): Selects all elements that are the parent of another element, including text.
$("li:contains(second)"): Selects all elements matched by
You can use all the above selectors with any HTML/XML element in generic way. For example if selector $("li:first") works for
element.
Please refer the below link
http://www.tutorialspoint.com/jquery/jquery-selectors.htm
Thanks
Anil KumarRank #367 · 6.8K reputationPosted May 9, 2012, 10:00 PM EDT
Go through all jQuery articles written by Satish.
http://www.c-sharpcorner.com/uploadfile/satisharveti/selectors-in-jquery/
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts