What are jQuery selectors?

<div id="main"><p class="note">A</p><p class="note">B</p><a href="/x">Link</a></div>
console.log($('#main').length);
console.log($('.note').length);
console.log($('p').length);
console.log($('a[href]').length);
console.log($('#main > p').length);
Console output

1
2
2
1
2

See jQuery Selectors.


Learn more about the similar topics:
Tutorials
jQuery Selectors
jQuery Traversing: Ancestors
jQuery Traversing: Descendants
jQuery Traversing: Siblings
jQuery Traversing: Filtering
Exercises & Assignments
Write jQuery code to count the items of a list
Write jQuery code to find the total of a table column
Write jQuery code to add alternate row colors to a table
Interview Questions & Answers
What are jQuery selectors?
What is the difference between find() and children() in jQuery?
What is the difference between parent(), parents() and closest() in jQuery?
How do you check if an element exists in jQuery?
What is the difference between this and $(this) in jQuery?
What is the use of end() in jQuery?