Mutual conversions between jquery objects and Dom objects

Source: Internet
Author: User

DOM objects: Dom (Document Object model), each DOM can be represented as a tree, DOM objects can use the methods in JavaScript.

jquery objects: jquery objects are objects that are produced after wrapping a DOM object through jquery. jquery objects are unique to jquery.

Dom objects and jquery objects cannot use each other's methods with each other, after conversion.

1. jquery objects into DOM objects

You can use the DOM object's method after you turn the jquery object into a DOM object. There are two types of conversions, [index] and get (index).

(1). The jquery object is an array-like object that can be obtained using the [index] method of the corresponding DOM object.

The jquery code is as follows:

var // jquery Object var cr= $cr [0];    // DOM Object
alert (cr.checked); Detects if the checked is selected

(2). Get the corresponding DOM object through the Get (index) method, which is provided by jquery itself.

var // jquery Object var cr= $cr. Get (0);    // DOM Object alert (cr.checked);    // detects if the checked is selected

2. DOM objects converted into jquery objects

After you convert the DOM object to a jquery object, you can use the method in jquery.

As long as you wrap the DOM object with $ (), you get a jquery object in the form of: $ (DOM), as shown here:

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

Knowledge points: The usual jquery objects are created by the $ () function, and the $ () function is a manufacturing facility for jquery objects.

Mutual conversions between jquery objects and 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.