The conversion of jquery objects to DOM objects

Source: Internet
Author: User

There have been some methods that have been used by jquery to make it impossible to directly use JavaScript, and it is not understood at the beginning, and now the case knows that the object that jquery obtained is not the same object that we normally get with getElementById. So some novice is very confused, why ${"#Element"} can not directly InnerHTML, this is the reason, the solution please see below.

conversion of jquery objects to DOM objects
only jquery objects can use the methods defined by jquery. Note that DOM objects are different from jquery objects, and you should be aware of whether you are manipulating DOM objects or jquery objects when calling methods.
Normal DOM objects can generally be converted to jquery objects through $ ().    can 500% improve the development efficiency of the front-end UI Framework!  

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 a jquery object is to be converted to a DOM object, it must take one of these items, which is generally available through the index.
Such as:

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

These are DOM objects, and you can use the methods in the DOM, but you can't use jquery any more. A front-end UI framework that can 500% improve development efficiency!
The following are the correct ways to do this:

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

The conversion of jquery objects to DOM objects

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.