Home >Web Front-end >JS Tutorial >Example code for conversion between jQuery objects and Javascript objects_jquery
1. Convert DOM object to jQuery object
For a DOM object that is already a DOM object, you only need to wrap the DOM object with $() to get a jQuery object, $(DOM object)
For example: var v = document.getElementById(“v”); //DOM object
var $v = $(v); //jQuery object
After conversion, you can use jQuery methods at will.
2. Convert jQuery object into DOM object
Two conversion methods convert a jQuery object into a DOM object: [index] and .get(index);
(1) The jQuery object is a data object, and the corresponding DOM object can be obtained through the [index] method.
For example: var $v = $(“#v”); //jQuery object
var v = $v[0]; //DOM object
alert(v.checked); //Check whether this checkbox is selected
(2) jQuery itself provides the corresponding DOM object through the .get(index) method
For example: var $v = $(“#v”); //jQuery object
var v = $v.get(0); //DOM object ($v.get()[0] can also be used)
alert(v.checked); //Check whether this checkbox is checked