The transformation of jquery objects and Dom objects

Source: Internet
Author: User

The transformation of jquery objects and Dom objects
Only jquery objects can use the method defined by jquery. Note that there is a difference between a DOM object and a jquery object, and the method is invoked with a DOM object or a jquery object in mind.
Ordinary DOM objects can generally be converted to jquery objects by $ ().

Such as:

$ (document.getElementById ("MSG"))

is a jquery object, you can use the jquery method.
Because the jquery object itself is a collection. So if the jquery object is to be converted to a DOM object, one of these items must be removed, which is generally accessible through the index.
Such as:

$ ("#msg") [0],$ ("div"). EQ (1) [0],$ ("div"). get () [1],$ ("TD") [5]

These are DOM objects that can use the methods in the DOM, but no longer use the jquery method.
The following are the correct ways to do this:

$ ("#msg"). html ();
$ ("#msg") [0].innerhtml;
$ ("#msg"). EQ (0) [0].innerhtml;
$ ("#msg"). Get (0). InnerHTML;

In the beginning, the case knows that the original jquery obtained object is not the same object as the object we usually get from using getElementById, since it is not possible to use JavaScript directly in the way that the object obtained through jquery has been used. So some novice is very confused, why ${"#Element"} can not directly innerHTML, this is the reason, the solution please see below.

The transformation of jquery objects and Dom objects
Only jquery objects can use the method defined by jquery. Note that there is a difference between a DOM object and a jquery object, and the method is invoked with a DOM object or a jquery object in mind.
Ordinary DOM objects can generally be converted to jquery objects by $ ().

Such as:

$ (document.getElementById ("MSG"))

is a jquery object, you can use the jquery method.
Because the jquery object itself is a collection. So if the jquery object is to be converted to a DOM object, one of these items must be removed, which is generally accessible through the index.
Such as:

$ ("#msg") [0],$ ("div"). EQ (1) [0],$ ("div"). get () [1],$ ("TD") [5]

These are DOM objects that can use the methods in the DOM, but no longer use the jquery method.
The following are the correct ways to do this:

$ ("#msg"). html ();
$ ("#msg") [0].innerhtml;
$ ("#msg"). EQ (0) [0].innerhtml;
$ ("#msg"). Get (0). InnerHTML;

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.