Before discussing the mutual exchange of jquery objects and Dom objects, agree on the style of defining variables. If you get an object that is a jquery object, add $ before the variable, for example:
Copy Code code as follows:
var $variable = jquery object;
If you get a DOM object, it is defined as follows:
Copy Code code as follows:
var variable = dom object;
1.jQuery objects into DOM objects
jquery objects cannot use methods in the DOM, but if you are unfamiliar with the methods provided by the JQuery object, or if jquery does not encapsulate the methods you want, and you have to practice DOM objects, there are two ways to do this. jquery provides two ways to convert a jquery object into a DOM object, that is, [index] and get (index).
(1) The JQuery object is an array object, and the corresponding DOM object can be obtained by the method [index].
The jquery code is as follows:
Copy Code code as follows:
var $CR = $ ("#cr"); jquery objects
var cr = $CR [0]//dom Object
Alert (cr.checked)//Detect if the checkbox is selected
(2) Another method is provided by jquery itself, and the corresponding DOM object is obtained through the Get (index) method.
The jquery code is as follows:
Copy Code code as follows:
[Js]var $CR = $ ("#cr");
var cr = $cr. Get (0);
Alert (cr.checked)
2.DOM object converted to jquery object
For a DOM object, it takes $ () to wrap the DOM object in order to get a jquery object, in the form of $ (DOM object).
The jquery code is as follows:
Copy Code code as follows:
var cr = document.getElementById ("Cr"); Dom Object
var $CR = $ (CR);
After conversion, you can use the methods in jquery in any way you want.
The above methods allow you to arbitrarily convert jquery objects and Dom objects to each other.
Finally, it is emphasized that DOM objects can use methods in the DOM, and jquery objects cannot use methods in the DOM, but the jquery object provides a more sophisticated tool for manipulating DOM