Home > Web Front-end > JS Tutorial > body text

How to convert js object to jquery object

藏色散人
Release: 2021-11-11 09:51:50
Original
6292 people have browsed it

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.

How to convert js object to jquery object

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();
Copy after login

It cannot be implemented because hide() is a method of the jquery object and the js object cannot be called.

②$("#text2").innerHTML = "jredu";
Copy after login

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.

How to convert js object to 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.

How to convert js object to jquery object

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!