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

Difference between jquery object and dom object

青灯夜游
Release: 2020-09-08 12:29:16
forward
1642 people have browsed it

Difference between jquery object and dom object

Related recommendations: "jQuery Video Tutorial"

There are a lot of judgment codes in recent work, using jquery and There are many places for dom objects. Let me write them here to strengthen the basic concepts:

1. When judging whether it exists, you must use the dom object, because when jQuery obtains an object, it will be used regardless of whether the object to be obtained exists or not. Return jQuery object

2. Conversion between jquery object and dom object:

The jQuery object is the object (collection object) generated by wrapping the DOM object through jQuery. The jQuery object is unique to jQuery and you can use the methods in jQuery.
Therefore, jQuery objects and DOM objects are different and cannot call methods defined by each other. Therefore, $(‘#test’).innerHTML will report an error, and document.getElementById(‘#test’)[0].html() will also report an error.

Ordinary DOM objects can be wrapped with $() and converted into jQuery objects:
$(document.getElementById('#test')).html();//Normal

jQuery object The jquery object itself is a collection. To be converted into a DOM object, it can be retrieved through the array index:
The first way: $('#test')[0]
The second way: $( '#test').get(0)
Note: eq(0) still returns a jQuery object, and eq(0)[0] is a DOM object.

For more programming-related knowledge, please visit: Programming Teaching! !

The above is the detailed content of Difference between jquery object and dom object. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
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