Home  >  Article  >  Web Front-end  >  Conversion between jQuery objects and DOM objects_jquery

Conversion between jQuery objects and DOM objects_jquery

WBOY
WBOYOriginal
2016-05-16 16:11:121103browse

1. Convert jQuery object into DOM object

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 have to use DOM objects, there are two ways to deal with them:

1. The jQuery object is an array-like object, and the corresponding DOM object can be obtained through the [index] method:

Copy code The code is as follows:

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 the get(index) method

Copy code The code is as follows:

var $cr=$("#cr") //jQuery object
var cr=$cr.get(0) //DOM object

2. Convert DOM objects into jQuery objects

For a DOM object, you only need to wrap the DOM object with $() to get a jQuery object.

Copy code The code is as follows:

var cr=document.getElementById("cr") //DOM object
var $cr=$(cr) //jQuery object

The above is the entire content of this article, I hope you all like it.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn