jQuery Selectors - Examples



Learn how to play with selectors in jQuery. Here are most commonly used examples −

  1. How to select all elements in the document?

  2. How to select all elements that are children of a paragraph element?

  3. How to get an element with id = "specialID"?

  4. How to get all the elements that have the class of specialClass?

  5. How to select all elements matched by <li> that do not have class="myclass"?

  6. How to match links with an id of specialID and a class of specialClass?

  7. How to match links with a class of specialClass declared within <p> elements?

  8. How to get only the first <li> element of the <ul>?

  9. How to select all elements matched by <p> that are descendants of an element that has an id of container?

  10. How to select all elements matched by <ul> that are children of an element matched by <li>?

  11. How to select all elements matched by <em> that immediately follow a sibling element matched by <strong>?

  12. How to select all elements matched by <ul> that follow a sibling element matched by <p>?

  13. How to select all elements matched by <code> or <em> or <strong>?

  14. How to select all elements matched by that are descendants of an element matched by <p> as well as all elements that have a class of myclass?

  15. How to select all elements that have no children?

  16. How to select all elements matched by <p> that have no children?

  17. How to select all elements matched by <div> that contain an element matched by <p>?

  18. How to select all elements matched by <p> that contain an element with a class of myclass?

  19. How to select all elements matched by <a> that have a rel attribute?

  20. How to select all elements matched by <input> that have a name value exactly equal to myname?

  21. How to select all elements matched by <input> that have a name value beginning with myname?

  22. How to select all elements matched by <a> that have rel attribute value ending with self?

  23. How to select all elements matched by <a> that have an href value containing domain.com?

  24. How to select all elements matched by <li> that have an even index value?

  25. How to select all elements matched by <tr> that have an odd index value?

  26. How to select the first <li> element?

  27. How to select the last <li> element?

  28. How to select all elements matched by <li> that are visible?

  29. How to select all elements matched by <li> that are hidden?

  30. How to select all radio buttons in the form?

  31. How to select all checked boxex in the form?

  32. How to select only form elements (input, select, textarea, button)?

  33. How to select only text elements (input[type=text])?

  34. How to select the third <li> element?

  35. How to select the fifth <li> element?

  36. How to select all elements matched by <li> element before the third one; in other words, the first two <li> elements?

  37. How to select all elements matched by <p> elements before the fourth one; in other words the first three <p> elements?

  38. How to select all elements matched by <li> after the second one?

  39. How to select all elements matched by <p> after the third one?

  40. How to select all elements matched by <li> that are the first child of their parent?

  41. How to select all elements matched by <li> that are the last child of their parent?

  42. How to select all elements that are the parent of another element, including text?

  43. How to select all elements matched by <li> that contain the text second?

Advertisements