Home > Article > Web Front-end > what is jquery object
The jquery object is an object that can be used to obtain page DOM elements through the jquery library's own methods. It is an object obtained using jquery's class library selector. It is an object generated by wrapping the DOM object through jquery; jquery objects can be used Methods in jquery, but DOM methods cannot be used.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
In the JQuery library, the object that can obtain the page DOM element through its own method is called a JQuery object. Objects are defined starting with var.
In the JQuery library, the object that can obtain page elements through its own method is called a JQurey object
The jQuery object is an object obtained using the jQuery class library selector. A JQuery object is an object generated by wrapping a DOM object with jQuery.
The JQuery object is unique to jQuery. It can use methods in jQuery, but cannot use DOM methods.
For example: $("#img").attr("src","test.jpg-600"); $("#img") here is the jQuery object.
Note: Any method of the DOM object cannot be used in the jQuery object.
For example, $("#id").innerHTML and $("#id").checked are wrong. You can use $("#id").html() and $ jQuery methods like ("#id").attr("checked") instead.
Similarly, DOM objects cannot use jQuery methods.
Convert DOM object into jQuery object
For a DOM object that is already a DOM object, you only need to wrap the DOM object with $() to get a jQuery object. , $(DOM object) Note: var is a method of defining variables
such as:
var v = document.getElementById(“v”); //DOM对象 var $v = $(v); //jQuery 对象
After conversion, you can use jQuery method arbitrarily.
Convert jQuery object to DOM object
Two conversion methods talk about converting a jQuery object into a DOM object: [index] and .get(index);
The jQuery object is a data object, and the corresponding DOM object can be obtained through the [index] method.
Such as:
var $v = $("#v"); //jQuery 对象 var v = $v[0]; //DOM 对象 alert(v.checked); //检测这个checkbox是否被选中
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of what is jquery object. For more information, please follow other related articles on the PHP Chinese website!