Sharp Jquery-1--jquery objects and Dom objects as well as mutual conversions

Source: Internet
Author: User

Dom object:

Document Object model, which can be represented as a tree by each part of the DOM.

As shown, the code is omitted

In this DOM tree, H3, P, UL, and UL's 3 Li subnodes are all DOM element nodes.

Get DOM object:

// get DOM Object var domobj = document.getElementById ("ID"); // using the JavaScript method var objhtml = domobj.innerhtml;

jquery object:

jquery objects are unique to jquery and are obtained by wrapping DOM objects in jquery.

// jquery method $ ("#foo"). html (); // equivalent to document.getElementById ("foo"). InnerHTML;

jquery object and Dom object transformations:

Jquery->dom:

The 1.jQuery object is an array object that can be obtained by [index] the corresponding DOM object

// conventions The jquery object's variables begin with $ to avoid confusion var $cr = $ ("#cr"//jquery object var cr = $CR [0];  // DOM Object alert (CR.checked);  // detects if the checkbox is selected

2. Get the DOM object through the jquery method get (Index).

// conventions The jquery object's variables begin with $ to avoid confusion var $cr = $ ("#cr"//jquery object var cr = $cr.Get( 0);  // DOM Object alert (CR.checked);  // detects if the checkbox is selected

Dom->jquery:

For a DOM object, the DOM object is wrapped up by $ () as a jquery object.

var cr = document.getElementById ("cr");  // DOM Object var $cr = $ (CR);  // jquery Object

Finally, again, DOM objects can use methods in the DOM, and jquery objects cannot use the methods in the DOM.

Sharp Jquery-1--jquery objects and Dom objects as well as mutual conversions

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.