Selectors are the foundation of jquery, in jquery, for event handling, traversing DOM and Ajax operations all depend on selectors
Advantages of the JQuery selector:
A concise notation
A perfect event handling mechanism
First, the basic selector
The basic selector is the most commonly used selector in jQuery and the simplest selector, which finds DOM elements by element ID, class, and tag name (the ID can only be used once in a Web page, and class allows for reuse).
Change the background color of the element with ID one to # BBFFAA
Change the background color of all elements of class Mini to # BBFFAA
Change the background color of all elements named <div> to # BBFFAA
Change the background color of all elements to # BBFFAA
Change all <span> elements and the background color of the element ID is # BBFFAA
Example:
<! DOCTYPE html>
Second, level selector
If you want to get specific elements through hierarchical relationships between DOM elements, such as descendant elements, child elements, neighboring elements, sibling elements, and so on, you need to use a hierarchy selector.
Note: (the "prev ~ div") selector can only select sibling elements that follow the "# prev" element; The method siblings () in JQuery is independent of the position, as long as it is a peer node can be selected
Change the background color of all <div> in <body> to # BBFFAA
Change <body> the background color of your wife <div> # BBFFAA
Change the background color of the next <div> ID for one to # BBFFAA
Change the background color of all brothers <div> elements behind the element ID is # BBFFAA
Change the element with ID to both all <div> sibling elements with a background color of # BBFFAA
Example:
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" >
Step-by-step learning JQuery (ii) selector: basic selector && Hierarchy Selector