This article mainly describes the jquery object and JS in the DOM object conversion between the method, so that the jquery object can be used directly in the JS method, or JS Dom object using the method in jquery.
jquery objects and Dom objects are not the same, what is a jquery object? What is a DOM object? Let us give an example:
$ ("#aijquery")://This way gets the jquery object document.getElementById ("Aijquery")://This method gets the DOM object
jquery objects are not the same as Dom objects, and some methods of objects are different, for example, we want to get the HTML content of a tag:
document.getElementById ("Aijquery"). innerhtml;//this is the method $ ("#aijquery") of the DOM object. HTML ();//This is the method of the jquery object
Sometimes we need to convert a jquery object into a DOM object, or convert a DOM object into a jquery object, in a particular case, and convert the two objects to each other:
The DOM object is converted to a jquery object:
In general, Dom objects can be converted to jquery objects directly with $ (), such as:
$ (document.getElementById ("Aijquery"))
jquery objects are converted to DOM objects in two ways, one of which is to use jquery's built-in function get to get DOM objects, such as:
$ ("#aijquery"). Get (0);
There is one more simple way to do this, because the properties of the JQuery object are a collection, so we can take one of them out as an array:
$ ("#aijquery") [0];$ ("div") [5];//above both return DOM objects, you can use the JS method directly
The conversion between jquery objects and Dom objects is the method above, summarizing some of the ways we often use them, and the following are all correct:
$ ("#aijquery"). html (); $ ("#aijquery") [0].innerhtml; $ ("#aijquery"). EQ (0) [0].innerhtml; $ ( "#aijquery"). Get (0). innerhtml;$ ("#aijquery"). EQ (2). HTML (); $ ("#aijquery"). Get (2). InnerHTML;
Original reference: Http://www.aijquery.cn/Html/jqueryjiqiao/11.html
Ways to convert jquery objects to and from DOM objects