This article mainly introduces the methods and examples of mutual conversion between jQuery objects and DOM objects, which is very practical. We recommend this article for your reference.
1. convert a jQuery object to a DOM object
JQuery objects cannot use methods in DOM, but if they are unfamiliar with the methods provided by jQuery objects, or jQuery does not encapsulate the desired methods, they must use DOM objects, there are two solutions:
1. The jQuery object is an array-like object. You can use the [index] method to obtain the corresponding DOM object:
The Code is as follows:
Var $ cr = $ ("# cr") // jQuery object
Var cr = $ cr [0] // DOM object
2. The other is provided by jQuery itself. get the DOM object through the get (index) method.
The Code is as follows:
Var $ cr = $ ("# cr") // jQuery object
Var cr = $ 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 Code is as follows:
Var cr = document. getElementById ("cr") // DOM object
Var $ cr = $ (cr) // jQuery object
The above is all the content of this article. I hope you will like it.