Conversion of Dom objects to jquery objects

Source: Internet
Author: User

The DOM object and the jquery object are always confused at first. Now make a summary of this:

DOM object: Document Object model. Each DOM can be seen as a tree. Like Ul,li ol DL P H1 and so on are DOM element nodes. These element nodes can be obtained through JS's getElementsByTagName and getElementById. Dom elements like this are DOM objects.


DOM objects can use the methods in JavaScript. Such as:


var domobj = document.getElementById ("id");

var objhtml = domobj.innerhtml;



The jquery object is the object that is generated after wrapping the DOM object through jquery.

jquery objects can use the methods in jquery. Such as:

$ ("#foo"). html ();

This code is equivalent to document.getElementById ("foo"). InnerHTML;


Of course, jquery objects and Dom objects can be converted to each other:

jquery provides two ways to convert a jquery object into a DOM object: [index] and get (index)


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

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


Now convert them to each other:

To convert a jquery object into a DOM object:

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

var cr = $CR [0]; Converts a jquery object into a DOM object.


To convert a DOM object into a jquery object:

var cr = document.getElementById ("Cr"); The DOM object is declared

var $CR = $ (CR); Convert a DOM object to a jquery object


It is usually the case that jquery does not encapsulate the method you want, but when you have to use a DOM object, you need to convert the jquery object into a DOM object.


Conversion of Dom objects to jquery 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.