Home > Article > Web Front-end > what is jquery selector
The jQuery selector is a powerful manifestation of jQuery. It provides a set of methods that allow us to obtain elements on the page more conveniently.
jQuery element selectors and attribute selectors allow you to select HTML elements by tag name, attribute name, or content.
Selectors allow you to operate on groups of HTML elements or individual elements.
In HTML DOM terms:
Selectors allow you to operate on groups of DOM elements or individual DOM nodes.
There are many types of jQuery selectors, let’s take a look.
jQuery Element Selectors
jQuery uses CSS selectors to select HTML elements.
$("p") Selects the
element.
$("p.intro") Selects all
elements with class="intro".
$("p#demo") Selects all
elements with id="demo".
jQuery Attribute Selector
jQuery uses an XPath expression to select elements with a given attribute.
$("[href]") Selects all elements with href attribute.
$("[href='#']") Selects all elements with an href value equal to "#".
$("[href!='#']") Selects all elements with an href value not equal to "#".
$("[href$='.jpg']") Gets all elements whose href value ends with ".jpg".
jQuery CSS Selectors
jQuery CSS selectors can be used to change CSS properties of HTML elements.
The following example changes the background color of all p elements to red:
$("p").css("background-color","red");
The above is the detailed content of what is jquery selector. For more information, please follow other related articles on the PHP Chinese website!