JavaScript native There are many ways, jquery itself has a set of packaged methods, jquery's own selector is very convenient, but sometimes we need to use some native methods, if we use jquery to select elements, The method of calling native JavaScript directly will cause an error. For example, we want to output the width of a picture:
Native JS:
Javascript:
var dom1 = document.getElementById ("Pic"). Width;
Alert (DOM1)
Jquery:
var dom2 = $ ("#pic"). width ();
Alert (DOM5)
Html:
Both methods can output the width of the image, but what if we want to use the jquery selector $ ("#pic") and use the native width method? If direct $ ("#pic"). Width is an error. The reason is that $ ("#pic") gets the jquery object, and the native width method is the DOM attribute, so you need to convert it:
$ ("#pic") [0].width or $ ("#pic"). Get[0].width
jquery Object Goto JS Object
$ (' #id ') [0]
JS object to jquery Object
var obj = document.getElementById (' id ');
$ (obj)
jquery uses the native JS method to Js/jquery objects to each other