Skip to content
jQuery

Selectors

Select elements by id, class, attribute, and pseudo-filters.

By EZ4Code Team
selectorsbasics

Code

// Basic selectors
$("#header");              // by id
$(".active");              // by class
$("div");                  // by tag
$("*");                    // all elements

// Combinators & attributes
$("ul li:first-child");    // first list item
$("a[href^='https']");     // links starting with https
$("input[type='checkbox']:checked");

// Form & content filters
$(":button");              // all buttons
$("div:contains('Hello')");
$("tr:odd");               // odd rows (zero-indexed)

Explanation

jQuery selectors mirror CSS selectors and add powerful pseudo-filters like :checked, :contains, and :odd. The factory function $() returns a matched set, which is array-like and chainable. Complex queries combine combinators, attributes, and filters for concise DOM targeting.

More jQuery Snippets