[Jquery tutorial] jquery Selector

Source: Internet
Author: User
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 the first <p> element 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:

$ ("P" ).css ("background-color", "Red ");

 

Jquery Selector
Selector Instance Select
* $ ("*") All elements
#ID $ ("# Lastname ") Id = "lastname" element
.Class $ (". Intro ") All class = "Intro" Elements
Element $ ("P ") All <p> Elements
.Class.Class $ (". Intro. Demo ") All class = "Intro" and class = "Demo" Elements
     
: First $ ("P: First ") First <p> element
: Last $ ("P: Last ") Last <p> element
: Even $ ("TR: Even ") All even <tr> Elements
: Odd $ ("TR: odd ") All odd <tr> Elements
     
: Eq (Index) $ ("Ul Li: eq (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 whose index is less than 3
: Not (Selector) $ ("Input: Not (: Empty )") All input elements not empty
     
: Header $ (": Header ") All title elements
: Animated   All animation Elements
     
: Contains (Text) $ (": Contains ('w3school ')") Contains all elements of a specified string
: Empty $ (": Empty ") All elements of a node without child (element)
: Hidden $ ("P: hidden ") All hidden <p> Elements
: Visible $ ("Table: visible ") All visible tables
     
S1, S2, S3 $ ("Th, TD,. Intro ") All elements with matching Selection
     
[Attribute] $ ("[Href]") All elements with href attributes
[Attribute=Value] $ ("[Href = '#']") The value of all href attributes is equal to the "#" element.
[Attribute! =Value] $ ("[Href! = '#'] ") The values of all href attributes are not equal to "#" elements.
[Attribute$ =Value] $ ("Your href00000000'.jpg ']") The values of all href attributes include ". jpg" elements.
     
: Input $ (": Input ") All <input> Elements
: Text $ (": Text ") All <input> elements of type = "text"
: Password $ (": Password ") All <input> elements of type = "password"
: Radio $ (": Radio ") All <input> elements of type = "radio"
: Checkbox $ (": Checkbox ") All <input> elements of type = "checkbox"
: Submit $ (": Submit ") All <input> elements of type = "Submit"
: Reset $ (": Reset ") All <input> elements of type = "reset"
: Button $ (": Button ") All <input> elements of type = "button"
: Image $ (": Image ") All <input> elements of type = "image"
: File $ (": File ") All <input> elements of type = "file"
     
: Enabled $ (": Enabled ") All activated input Elements
: Disabled $ (": Disabled ") All disabled input Elements
: Selected $ (": Selected ") All selected input Elements
: Checked $ (": Checked ") All selected input 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.