When learning jquery for the first time, you often cannot distinguish between DOM objects and Jquery objects. Let’s briefly explain the relationship and difference between them
1.DOM object (Document Object Model)
Document Object Model, each DOM can be represented as a tree. For example, the following is a simple web page code:
expressed as DOM:
We can get the nodes in the tree through getelementsByTayName or getelementsByTayId in JS. The elements obtained like this are DOM objects. DOM can use methods in JS, for example:
Jquery object is an object generated by wrapping DOM object with Jquery. It is unique to Jquery and can call methods in jquery, for example:
$("#foo").HTML();
Before we convert them, we must first specify the style of defining variables. For example, when defining a Jquery object, add a $ symbol, for example:
var $obj=Jquery对象
var domobj=DOM对象
var $obj=$("#sc"); var obj=$obj[0]; alter(obj.checked);
var $obj=$("#sc"); var obj=$obj.get(0); alter(obj.checked);
The DOM object can be converted into a Jquery object through $(), for example:
var obj=document.getelementsByTayName("Name"); var $obj=$(obj);