Jquery Filtering

Jquery Filtering

jQuery offers a wide range of filtering methods to help you easily and efficiently manipulate and traverse the elements of an HTML document. Here are some of the most commonly used filtering methods:

  1. :first – Selects the first element in the set of matched elements.
  2. :last – Selects the last element in the set of matched elements.
  3. :even – Selects even-indexed elements in the set of matched elements.
  4. :odd – Selects odd-indexed elements in the set of matched elements.
  5. :eq(n) – Selects the element at index n within the set of matched elements.
  6. :gt(n) – Selects elements with an index greater than n within the set of matched elements.
  7. :lt(n) – Selects elements with an index less than n within the set of matched elements.
  8. :not(selector) – Selects all elements that do not match the given selector.
  9. :has(selector) – Selects elements that have at least one descendant that matches the given selector.
  10. :contains(text) – Selects elements that contain the specified text.

Here is an example of how to use some of these filtering methods:

// Select all even-indexed paragraphs on the page and hide them
$("p:even").hide();

// Select all input elements except for the ones with the "disabled" attribute
$("input:not([disabled])").css("background-color", "yellow");

// Select all elements that contain the text "Lorem" and change their font size
$(":contains('Lorem')").css("font-size", "18px");

These are just a few of the many filtering methods that jQuery offers. You can find a full list of filtering methods in the jQuery documentation.

Scroll to Top