2. jquery Selector

Source: Internet
Author: User

Recommended learning resources from: Zhang Ziqiu http://www.cnblogs.com/zhangziqiu/tag/jQuery%e6%95%99%e7%a8%8b/

Summary:

In the previous example, we have the ID selector $ ("# btnshow") to capture controls on the page. This article describes how to use selector to capture elements and objects. $ Is short for jquery.

Content:

The jquery selector is used to capture objects on the page and return them in the form of a jquery package set.

Note the differences between DOM objects and wrapper sets:

Vardiv = Document. getelementbyid ("testdiv ");

Vardivs = Document. getelementbytagname ("Div"); these are DOM objects

 

Vardivs = $ (divs );

Vardiv = $ ("# testdiv"); // jquery package set, either a or a group

 

Vard = $ ("# Div") [0]; get the first one in the set. In this case, the returned Dom is not the jquery package set.

$ ("# Div"). Each (function () {alert (this)}); The Traversal method included in jquery. For example, each will pass the traversal Function

 

Use of the jquery selector:

1. Basic Selector

$ ("# Divid"): select the element whose ID is divid.

$ ("A"): select all <A> Elements

$ (". Bgred"): select all elements whose CSS class is bgred.

$ ("*"): Select all elements

$ ("# Divid, A,. bgred"): the matching contents of these selectors are selected at the same time.

2. Hierarchical Selector

3. Basic filter Selector

$ ("# Div: First"): matches and finds the first element with the ID Div.

$ ("TR: Last"): Find the last row of the table

......

4. Content Filter

$ ("Div: Has (p)"). addclass ("test"): adds a test class to all DIV elements containing the P element.

...

5. Visibility Filtering

6. Attribute Filtering

7. subelement Filtering

8. Select a form

9. Form Filtering

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.