JQuery selector (3)

Source: Internet
Author: User
Tags element groups

In the previous section, the jQuery selector shows examples of 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, 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. 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 ") the jQuery selector instance Selects all elements of * $ ("*") # id $ ("# lastname") id = "lastname. class $ (". intro ") all elements of class =" intro "$ (" p ") All <p> elements. class. class $ (". intro. demo ") All class =" intro "and class =" demo "elements: first $ (" p: first ") the first <p> element: last $ (" p: last ") last <p> element: even $ (" tr: even ") All even <tr> element: odd $ (" tr: odd ") all odd <tr> elements: eq (index) $ ("ul li: e Q (3) ") The fourth element in the list (index starts from 0): gt (no) $ (" ul li: gt (3 )") list elements with an index greater than 3: lt (no) $ ("ul li: lt (3)") list elements with an index less than 3: not (selector) $ ("input: not (: empty) ") All input elements not empty: header $ (": header ") All title elements

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.