The sample code for converting between a jQuery object and a Javascript Object. For more information, see
The Code is as follows:
I would like to share some of the following with you. I love programming and hope to be more programmers. If you are one of them, please add your friends, the following articles are useful things for you. You can take notes for yourself and hope to help you. Thank you for reading them first ~!
If jQuery is used as the script on the client page, mutual conversion between jQuery objects and Javascript objects is often involved. Because DOM objects are some object operations inherent in Javascript. DOM objects can use Javascript's inherent methods, but they cannot use the methods in jQuery. Therefore, we will share a little bit of Code Conversion between them for your learning and reference.
1. convert a DOM object to a jQuery object
For 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 the jQuery method at will.
2. convert a jQuery object to a DOM object
Two conversion methods: converting a jQuery object to a DOM object: [index] And. get (index );
(1) The jQuery object is a data object. You can use the [index] method to obtain the corresponding DOM object.
For example, var $ v =$ ("# v"); // jQuery object
Var v = $ v [0]; // DOM object
Alert (v. checked); // checks whether the checkbox is selected.
(2) jQuery itself provides a DOM object that can be obtained through the. get (index) method.
For example, var $ v =$ ("# v"); // jQuery object
Var v = $ v. get (0); // DOM object ($ v. get () [0)
Alert (v. checked); // checks whether the checkbox is selected.