jquery Property Selector (matches the element with the specified attribute) _jquery

Source: Internet
Author: User
Tags element groups tag name

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.