JQuery Selector
In the previous chapters, we showed some examples of how to select HTML elements.
The key point is to learn how the JQuery selector accurately selects the elements that you want to apply the effect to.
The JQuery element selector and the property selector allow you to select HTML elements by tag name, property name, or content.
Selectors allow you to manipulate HTML element groups or individual elements.
In the HTML DOM terminology:
The selector allows you to manipulate a DOM element group or a single DOM node.
JQuery element Selector
JQuery uses the CSS selector to select HTML elements.
$ ("P") select <p> element.
$ ("P.intro") selects all <p> elements of the class= "Intro".
$ ("P#demo") selects all <p> elements of Id= "demo".
JQuery Property Selector
JQuery uses an XPath expression to select an element with the given property.
$ ("[href]") selects all elements with the href attribute.
$ ("[href= ' # ']") selects all elements with an HREF value equal to "#".
$ ("[href!= ' # ']") selects all elements with an HREF value that is not equal to "#".
$ ("[href$= '. jpg ']") selects elements with all href values ending with ". jpg".
JQuery CSS Selector
The JQuery CSS selector can be used to change the CSS properties of HTML elements.
The following example changes the background color of all p elements to red:
Instance
$ ("P"). CSS ("Background-color", "Red");
More examples of selection
Grammar |
Description |
$ (This) |
Current HTML Element |
$ ("P") |
All <p> elements |
$ ("P.intro") |
<p> Elements of all class= "Intro" |
$ (". Intro") |
All elements of the class= "Intro" |
$ ("#intro") |
id= Elements of "Intro" |
$ ("ul Li:first") |
The first <li> element of each <ul> |
$ ("[href$= '. jpg ']") |
All href attributes with attribute values ending with ". jpg" |
$ ("Div#intro. Head") |
id= Elements of all class= "Head" in the <div> element of "Intro" |
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The above is the jquery attribute selector data collation, follow-up continue to supplement the relevant information, thank you for your support of this site!