How to convert dom object into jquery object

青灯夜游
Release: 2022-03-11 15:32:41
Original
4509 people have browsed it

How to convert a dom object into a jquery object: Just use "$()" to wrap the DOM object, the syntax is "$(DOM object)"; after conversion, you can use jQuery arbitrarily method.

How to convert dom object into jquery object

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

DOM object

DOM (Document Object Model, Document Object Model), each DOM can be represented as a tree. Let’s look at a simple example first: The code is as follows

// ...省略其他代码

例子

你最喜欢的水果是?

  • 苹果
  • 橘子
  • 菠萝
// ...省略其他代码
Copy after login

describes the above HTML structure as a DOM tree:

How to convert dom object into jquery object

The nodes in this DOM tree are Is a DOM element node. You can get the element node through getElementByTagName or getElementById in JS. The DOM element obtained like this is a DOM object.

jQuery object

jQuery object is an object generated by wrapping a DOM object through jQuery.

jQuery objects are unique to jQuery. If an object is a jQuery object, then you can use the methods in jQuery. Any method of the DOM object cannot be used in the jQuery object, and the same DOM object cannot use the methods in jQuery.

How to convert a dom object into a jquery object

For a DOM object, you only need to wrap the DOM object with $() to get a jQuery object . The method is $(DOM object). After conversion, you can use any method in jQuery.

Note: The jQuery objects commonly used are manufactured through the $() function. The $() function is a manufacturing factory for jQuery objects.

The jquery code is as follows:


  

my

my

Copy after login

After conversion, you can use any jquery method.

Through the above methods, jquery objects and DOM object web page effects can be converted to each other at will.

Finally, I emphasize again that only DOM objects can use DOM methods. jquery objects cannot use methods in DOM, but jquery objects provide a more complete set of tools for operating DOM.

[Recommended learning: jQuery video tutorial, web front-end video]

The above is the detailed content of How to convert dom object into 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!