Preface:
In the previous blog "jquery Overview 1 -- jquery related Introduction", we have seen some examples of creating a package through jquery instances, but they are not complete. In this article, we refer to several creation methods, in addition, on the basis of classification, we can achieve better understanding.
Use the basic CSS selector:
With reference to the selector in CSS, you can obtain the elements directly through them in jquery. The following lists some examples:
- A -- This selector matches all links <A> elements;
- # Specialid -- This selector matches the element whose ID is specialid;
- . Specialclass -- This selector matches all CSS class specialclass elements;
- A # specialid. specialclass -- This selector matches idweispecialid and has the link element of CSS specialclass;
- P a. specialid -- This selector matches all the link elements of the CSS specialclass and within the <p> element;
Sub-selector, container selector, and feature selector:
Sub-selector:
< Body >
< Form ID = " Form1 " Runat = " Server " >
< Div >
< Ul class = " Mylist " >
< Li > < A href = " Http://www.baidu.com " > Baidu < / A> < / Li >
< Ul >
< Li > < A href = " Http://www.sina.com.cn " > Sina < / A> < / Li >
< Li > < A href = " Http://www.sohu.com " > Sohu < / A> < / Li >
< / Ul>
< / Ul>
< / Div>
< / Form>
< / Body>
In this case, if the application selector:
$ ("Ul. mylist Li ")
At this time, the element set we selected is all links that contain Baidu, Sina, and Sohu, because the three are the descendant nodes of Li that meet the conditions of the horse.
If we only want to select the node link of Baidu, what should we do? Fortunately, jquery providesSub-selector:Pass:
$ ("Ul. mylist> LI> ")
The sub-selector (method:>) is used to implementDirect subnodeElement selection.
Feature selector:
For example:
$ ("A [href ^ = http: //]")
That is, select all the links that contain the href feature and start with http: // <A> element. ^ = Is only one type. For more information, see the list:
Include selector:
For example:
$ (Li: has ())
That is, select all <li> elements that contain <A> elements. This is the include selector (that is, the container selector ).
Location selector:
In the previous blog post "jquery Overview 1 -- jquery Introduction", we applied it:
$ ("Table TR: Nth-child (even)"). Addclass ("Even")
This applies to the location selector.
In summary, the preceding selectors are the basic methods for obtaining the package set. The next section will continue.How to operate elements in a package set...