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 |