Home > Article > Web Front-end > How to convert js object to jquery object
Methods for converting js objects to jquery objects: 1. Define a js object with the object name "jsObj"; 2. Convert the js object to a jquery object through the "var jqueryObj = $(jsObj);" method. Can.
The operating environment of this article: windows7 system, jquery3.2.1 version, DELL G3 computer
How to convert js objects to jquery objects?
Conversion of JS objects and Jquery objects
JS type objects and jquery type objects are two completely different objects. However, the methods of the two objects cannot call each other. So what should I do if the js object wants to call a method in jquery, or if the jquery object wants to call a js method? This time involves the issue of mutual conversion between js objects and jquery objects.
For example:
①document.getElementById("text").hide();
It cannot be implemented because hide() is a method of the jquery object and the js object cannot be called.
②$("#text2").innerHTML = "jredu";
The same cannot be achieved because innerHTML is The properties of js objects cannot be used by jquery objects.
Then, let me introduce to you how to realize the mutual conversion between js and jQuery:
---Conversion 1: Convert js object into jquery object
- --Conversion 2: Convert jquery object into js object
1. Convert js object into jquery object:
--$(): jquery object conversion factory, which can convert js object into jquery object.
2. Convert the jquery object into a js object:
The elements obtained through $() are It is of array type. You can get the elements in the array through index, and the obtained elements are of js type.
Through the above two conversions, the function of mutual calling can be achieved
Recommended learning: " jquery video tutorial》
The above is the detailed content of How to convert js object to jquery object. For more information, please follow other related articles on the PHP Chinese website!