Jquery attribute selector (matching elements with specified attributes) and jquery Selector
JQuery Selector
In the previous section, we showed some examples about how to select HTML elements.
The key point is to learn how the jQuery selector accurately selects the elements you want to apply.
The jQuery element selector and attribute selector allow you to select HTML elements by Tag Name, attribute name, or content.
The selector allows you to operate on HTML element groups or individual elements.
In html dom terminology:
The selector allows you to operate a DOM element group or a single DOM node.
JQuery element Selector
JQuery uses the CSS selector to select HTML elements.
$ ("P") Select the <p> element.
$ ("P. intro") select all <p> elements of class = "intro.
$ ("P # demo") select all <p> elements of id = "demo.
JQuery attribute Selector
JQuery uses an XPath expression to select an element with a given attribute.
$ ("[Href]") selects all elements with the href attribute.
$ ("[Href = '#']") select all elements with an href value equal.
$ ("[Href! = '#'] ") Select all elements with an href value not equal.
$ ("Your href00000000'.jpg ']") select all elements whose href values end with ". jpg.
JQuery CSS Selector
The jQuery CSS selector can be used to change the CSS attributes of HTML elements.
The following example changes the background color of all p elements to Red:
Instance
$ ("P" ).css ("background-color", "red ");
More select instances
Syntax |
Description |
$ (This) |
Current HTML Element |
$ ("P ") |
All <p> Elements |
$ ("P. intro ") |
All <p> elements of class = "intro" |
$ (". Intro ") |
All class = "intro" Elements |
$ ("# Intro ") |
Id = "intro" element |
$ ("Ul li: first ") |
The first <li> element of each <ul> |
$ ("Your href00000000'.jpg ']") |
All href attributes with attribute values ending with ". jpg" |
$ ("Div # intro. head ") |
All the elements of class = "head" in the <div> element of id = "intro" |
<! DOCTYPE html PUBLIC "-// W3C // dtd xhtml 1.0 Transitional // EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
The above is to sort out information about the jquery attribute selector. We will continue to add relevant information in the future. Thank you for your support for this site!