Basic Filter Selectors


SelectorExampleDescription
:first$("p:first")Selects the first <p> element.
:last$("p:last")Selects the last <p> element.
:even$("tr:even")Selects all even <tr> elements, zero-indexed.
:odd$("tr:odd")Selects all odd <tr> elements, zero-indexed.
:eq()$("tr:eq(1)")Select the 2nd <tr> element within the matched set, zero-based index.
:not()$("p:not(:empty)")Select all <p> elements that are not empty.
:lt()$("ul li:lt(3)")Select all <li> elements at an index less than three within the matched set (i.e. selects 1st, 2nd, 3rd list elements), zero-based index.
:gt()$("ul li:gt(3)")Select all <li> elements at an index greater than three within the matched set (i.e. selects 4th, 5th, … list elements), zero-based index.
:header$(":header")Selects all elements that are headers, like <h1><h2><h3> and so on.
:lang()$(":lang(en)")Selects all elements that have a language value “en” i.e. lang="en"lang="en-us" etc.
:root$(":root")Selects the document’s root element which is always <html> element in a HTML document.
:animated$(":animated")Select all elements that are animating at the time the selector is run.

Leave a Reply

Your email address will not be published. Required fields are marked *