Learn jquery from scratch (ii) a universal selector

Source: Internet
Author: User
Tags tag name wrapper

I. Summary

This chapter explains the knowledge of the most important selector parts of jquery. With the jquery selector we can get almost any one or a group of objects on the page, which can significantly reduce the developer's workload.

Two. Foreword

To write any JavaScript program we want to get the object first, the jquery selector can completely change the way we usually get the object and get almost any semantic object, such as "owning the title property and the <a> element containing the test in the value." The only way to do this is to write a jquery selector string. Learning the jquery selector is the most important step in learning jquery.

Three. Dom objects and jquery wrapper sets

Whether you're writing a program or looking at an API document, we should always be careful to differentiate between DOM objects and jquery wrapper sets.

1.Dom objects

In traditional JavaScript development, we all get DOM objects first, such as:

var div = document.getElementById("testDiv");
var divs = document.getElementsByTagName("div");

We often use the document.getElementById method to get a single Dom object from an ID, or we use the document.getElementsByTagName method to get a collection of Dom objects based on the HTML tag name.

Additionally, in an event function, you can use this reference event to trigger an object in a method function (but there is a problem with IE6 in the multicast event function), or use the event object's target (FF) or srcelement (iIE6) to get to the DOM object that raised the event.

Notice what we get here are DOM objects, and Dom objects have different types such as input, Div, span, and so on. Dom objects have only a limited number of properties and methods:

2.jQuery Packing Set

The jquery wrapper set can be said to be an extension of the DOM object. In the jquery world, all objects, whether one or a group, are encapsulated into a jquery wrapper set, such as a jquery wrapper set containing an element:

var jQueryObject = $("#testDiv");

The jquery wrapper set is called together as an object. The jquery wrapper set has rich properties and methods that are unique to jquery:

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.