Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - What is the difference between jQuery and DOM objects, and how to convert them?
What is the difference between jQuery and DOM objects, and how to convert them?
What this paper brings to you is the difference and mutual transformation between jQuery object and DOM object, which is an important knowledge point in the process of learning front-end knowledge. Friends in need can refer to it and hope to help you.

How to get DOM objects and jQuery objects

The meaning of DOM object: the object returned by using the method in JavaScript to obtain the elements in the page is DOM object. JavaScript tutorial

Common methods to get DOM objects:

Vardemo1= document. getelementsbyclassname ("demo1")//Get the class node.

Vardemo2 = document. Getelementbyid(" demo 2 ")// Get the id node.

Vardemo3 = document. Getelementsbytagname ("demo 3")//Get the meaning of the label node jQuery object: Use the method in jQuery to get the object returned by the page, which is the jQuery object. JQuery tutorial

How to get the jQuery object:

Var $ obj1= $ (".obj1")//Get the class node.

Var $obj2=$("#obj2")// Get the ID node.

Var $obj3=$("obj3")// Get the difference between the label node jQuery object and DOM object.

JQuery object is an array belonging to js, which is basically a wrapper set of DOM objects, including a collection of DOM objects.

Note: The methods and properties of jQuery objects and DOM objects cannot be mixed. Next, we will introduce the transformation between these two objects.

Transformation between jQuery object and DOM object.

Convert DOM objects to jQuery objects:

var demo = document . getelementsbytagname(" demo ");

$ demo = $(demo); //is a typical DOM object of jQuery object.

Convert jQuery object to DOM object:

var $ obj = $(" obj ");

$ obj[0]; //Method 1 (common)

$ obj . get(0); //Summary of Method 2: