jquery objects converted to DOM objects
Only jquery objects can invoke the various functions of the JQuery class library, and the properties and methods of some DOM objects cannot be invoked on jquery, but basically the functions provided by the JQuery class library contain all the DOM operations.
The index of the jquery object holds the DOM object, so you can convert the jquery object into a DOM object by index (actually get the DOM object saved in the JQuery object).
$ ("#myphoto") [0];
When you return a DOM object by index, you can use the methods and properties of various DOM objects, such as getting the SRC attribute of a DOM object:
Alert ($ ("#myphoto") [0].SRC];
If you want to traverse each element in a jquery object, you typically use the each () function.
Echo (callback);
Callback () is a callback function, which in this function also points to the DOM element.
$ ("#myphoto"). each (function (i) {
this,src= "Test" +i+ ". jpg";
});
Dom object converted to jquery object
If you have already obtained a DOM object, you can use the jquery (elements) function to convert it to a jquery object:
Var Img=document.getelementbyid ("Myphoto");
JQuery (IMG). CSS ("border", "solid 2px #FF0000");
In the code above, IMG is the DOM object obtained using the DOM. After you convert it to a jquery object, you can change its style using the jquery object's CSS () method.
You can use "$" instead of "jquery," because within jquery there are the following implementations:
jquery=window.jquery=window.$
The "$" character can be used as a variable name in JavaScript and may appear as a prefix. However, some other class libraries or programs may have used the "$" as the variable name.
JQuery (IMG). CSS ("border", "solid 2px #FF0000");
$ (IMG). CSS ("border", "solid 2px #FF0000");
The above two statements are equivalent.
The elemients parameter of the jquery (elements) function can also be a jquery object, although it is not meaningful to say that a jquery object is converted in the second, in order to not be sure whether the type of an object is a jquery object or a DOM object. You can call this function again to convert, which guarantees that this object must be a jquery object.
Conversion of jquery objects and Dom objects to and from each other "go"