Before discussing the exchange of jQuery objects and DOM objects, first agree on the style of defining variables. If the obtained object is a jQuery object, add $ before the variable, for example:
jQuery objects cannot use methods in DOM, but if you are not familiar with the methods provided by jQuery objects, or jQuery does not encapsulate the desired methods, and you have to use DOM objects, there are two methods below. jQuery provides two methods to convert a jQuery object into a DOm object, namely [index] and get(index).
(1) The jQuery object is an array object, and the corresponding DOM object can be obtained through the [index] method.
The jQuery code is as follows:
The jQuery code is as follows:
For a DOM object, you only need to wrap the DOM object with $() to get a jQuery object. The method is $(DOM object).
The jQuery code is as follows:
Through the above methods, jQuery objects and DOM objects can be converted to each other arbitrarily.
Finally, it is emphasized that only DOM objects can use methods in DOM. jQuery objects cannot use methods in DOM, but jQuery objects provide a more complete set of tools for operating DOM