Home  >  Article  >  Web Front-end  >  What is the difference between jquery objects and js objects

What is the difference between jquery objects and js objects

WBOY
WBOYOriginal
2022-06-14 18:56:553600browse

The difference between jquery objects and js objects: 1. The jquery object is a unique object of jquery. It will exist only if jquery is called. The js object is an unordered collection of name-value pairs and will exist if jquery is not called. ; 2. The methods on the js object cannot be used directly on jquery. The jquery object needs to be converted into a js object before it can be used. However, the jquery object can use the methods defined by jquery at will.

What is the difference between jquery objects and js objects

The operating environment of this tutorial: windows10 system, jquery3.6.0 version, Dell G3 computer.

What is the difference between jquery object and js object

Difference:

JS object is an unordered collection of name-value pairs .

The jquery object is a jquery-specific object that only exists when the jquery framework is called. In fact, the jquery object is also a js object.

jquery objects and js objects can be converted to each other. For example,

$("#div").get() can convert a jquery object into a js object.

The main difference is that the methods on the js object cannot be used directly on the jquery object. If you must use the js object method for the jquery object, you must convert the jquery object into a js object. jquery object, you can use the methods defined by jquery at will.

The js object is an object obtained through dom operation, which refers to a label object on the page;

The jQuery object is an array-like object obtained through jQuery, which contains There are JS objects;

js objects can only access predefined methods in the DOM, and jquery objects can only call methods provided by jQuery.

Extended knowledge:

Convert JS objects and jQuery objects to each other;

Convert JS objects to jQuery objects:

<script type="text/javascript">
    //获取dom对象
    var jsObj = document.getElementById("inpId");
    //将dom对象转化成jQuery对象
    var jqObj = $(jsObj);</script>

jQuery object into JS object:

<script type="text/javascript">
    //获取jQuery对象
    var jqObj = $("#inpId");
    //将jQuery对象转化成JS对象
    //方式一:
    var jsObj1 = $inp[0];
    //方式二:
    var jsObj2 = $inp.get(0);
 </script>

Recommended video tutorial: jQuery video tutorial

The above is the detailed content of What is the difference between jquery objects and js objects. For more information, please follow other related articles on the PHP Chinese website!

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