Home >Web Front-end >JS Tutorial >what is jquery selector

what is jquery selector

(*-*)浩
(*-*)浩Original
2019-05-21 09:42:1010396browse

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.

what is jquery selector

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn