Jquery development: mutual conversion between jQuery objects and DOM objects, jquerydom
If the obtained object is a jQuery object, add $ before the variable, as shown below:
Var $ variable = jQuery object
If a DOM object is obtained, the definition is as follows:
Var variable = DOM object
1. convert a jQuery object to a DOM object
JQuery provides two methods to convert a jQuery object to a DOM object: [index] And get (index)
(1) The jQuery object is an array-like object. You can use the [index] method to obtain the corresponding DOM object. The jQuery code is as follows:
Var $ cr = $ ("# cr"); // jQuery object var cr = $ cr [0]; // DOM object
(2) The other method is provided by jQuery itself. get the DOM object through the get (index) method. The jQuery code is as follows:
Var $ cr = $ ("# cr"); // jQuery object var cr = $. get (0); // DOM object
2. convert a DOM object to a jQuery object
For a DOM object, you only need to wrap the DOM object with $ () to obtain a jQuery object. The jQuery code is as follows:
Var cr = document. getElementById ("cr"); // DOM object var $ cr = $ (cr); // jQuery object