2nd Chapter SELECT Element
1. Use the $ () function
The $ () function is actually creating a jquery object. This function takes a CSS selector as a parameter, acts as a factory, and returns a JQuery object that contains the corresponding elements in the page. All selectors that can be used in a style sheet can be passed to this function, and then the jquery method can be applied to the set of matching elements.
In jquery, dollar sign $ is actually the "alias" of the identifier jquery.
2. Selectors
1. Base Selector $ (' P ')//get all the elements labeled P$ ('. Class ')//get all classes of class elements$ (' #id ')//gets the element with ID as ID //and other selectors in the CSS2The . Property Selector $ (' Img[alt] ')//Select all image elements with an ALT attribute //^ represents the value at the beginning of the string, which represents the value at the end of the string. * indicates that the value to be matched can appear anywhere in the string! Indicates that the value is reversed$ (' a[href^= ' mailto: "])//Select all mailto in page: Link$ (' a[href$= '. pdf "])//Select links to all PDF documents on the page$ (' a[href^= ' http "][href*=" Henry "])//Select the href attribute to start with HTTP and include Henry's Elements anywhere3. Custom Selectors $ (' Div.horizontal:eq (1) ')//gets the second element in a collection$ (' Tr:even ')//select Odd rows. The odd line is because the first row is numbered 0.$ (' Tr:nth-child (odd) ')//select odd lines.: Nth-child () is the only selector in JQ that counts from 1$ (' Tr:contains (Henry) ')//selects elements based on context content. Contains selectors are case-sensitive4. The form-based selector $ (' Input[type= ' Radio "]:checked")//You can select all the selected radio buttons$ (' input[type= "text"]:d isabled ')//Select a disabled text entry field
More form-based selectors
: Input : Button : Enabled :d isabled : checked:selected
3. Dom Traversal method
"Basic jquery Tutorial (fourth edition)" Learning notes