Conversion between jQuery objects and DOM objects
- 2020-05-10 17:41:19
- OfStack
1. Convert jQuery object into DOM object
The jQuery object cannot use the methods in DOM, but if you are not familiar with the methods provided by the jQuery object, or jQuery does not encapsulate the desired method, you have to use the DOM object in the following two ways:
1. The jQuery object is an array like object, and the corresponding DOM object can be obtained by [index] method:
var $cr=$("#cr") //jQuery object
var cr=$cr[0] //DOM object
2. The other one is provided by jQuery itself, and the corresponding DOM object is obtained through get(index) method
var $cr=$("#cr") //jQuery object
var cr=$cr.get(0) //DOM object
2. Convert DOM objects into jQuery objects
For 1 DOM object, you can get 1 jQuery object by wrapping the DOM object with $().
var cr=document.getElementById("cr") //DOM object
var $cr=$(cr) //jQuery object
That's all for this article, I hope you enjoy it.