Jquery Overview 2 -- create an element package set

Source: Internet
Author: User


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:



< 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...

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.