Jquery attribute selector (matching elements with specified attributes) and jquery Selector

Source: Internet
Author: User
Tags element groups

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!

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.