Analysis of the differences between jquery objects and Dom objects

Source: Internet
Author: User

If you get an object that is a jquery object, add $ before the variable, for example:

The

code is as follows:


var $variable = jquery object;

If you get a DOM object, it is defined as follows:

The

code is as follows:


var variable = dom object;



jquery objects cannot use methods in the DOM, but if you are unfamiliar with the methods provided by the JQuery object, or if jquery does not encapsulate the methods you want, and you have to practice DOM objects, there are two ways to do this. jquery provides two ways to convert a jquery object into a DOM object, that is, [index] and get (index).

1. The jquery object is an array object, and the corresponding DOM object can be obtained by means of [index].

The

code is as follows:


var $CR = $ ("#cr"); jquery Object


var cr = $CR [0]//dom Object


alert (cr.checked)//Detect if the checkbox is selected

2, the corresponding DOM object is obtained by Get (index) method.

The

code is as follows:


var $CR = $ ("#cr");


var cr = $cr. Get (0);


alert (cr.checked);

For a DOM object, it takes $ () to wrap the DOM object in order to get a jquery object, in the form of $ (DOM object).

The

code is as follows:


var cr = document.getElementById ("Cr"); Dom Object


var $CR = $ (CR);

Summarize:

The Get method in the JQuery method is in fact getting the DOM element ($ (this). Gets (0) and $ (this) [0])

The EQ, the top and the last methods in the JQuery method are all the jquery objects that are returned

Third, Dom objects can use methods in the DOM, and jquery objects cannot use methods in the DOM. The jquery object provides a more complete set of tools for manipulating the DOM.

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.