What is a DOM object?
HTML organizes documents in a tree structure, as follows:
Copy Code code as follows:
<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<title>1-4</title>
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 "/>
<!--introduction of JQuery-->
<script src= ". /scripts/jquery-1.3.1.js "type=" Text/javascript "></script>
<script type= "Text/javascript" >
Wait for the DOM element to finish loading.
$ (document). Ready (function () {
var domobj = document.getElementsByTagName ("h3") [0]; Dom Object
var $jQueryObj = $ (domobj); jquery objects
Alert ("Dom object:" +domobj.innerhtml);
Alert ("jquery object:" + $JQUERYOBJ. html ());
});
</script>
<body>
<p title= "Choose your favorite fruit." > Your favorite fruit is?</p>
<ul>
<li> Apple </li>
<li> Orange </li>
<li> Pineapple </li>
</ul>
</body>
The DOM tree for the above HTML file is as follows:
What is a jquery object?
The jquery object is the DOM object that has been wrapped in jquery, as follows:
$ (domobj) equivalent to document.getElementsByTagName ("H3")
$ ("#ID") equivalent to Document.getelementsbyid ("ID")
the transformation of jquery objects and Dom objects?
1. Get Objects:
Get jquery object: var $variable =jquery object;
Gets the DOM object: Var Variable=dom object;
2.jQuery object to DOM object:
convert var cr=$ ("#cr") using an array [0];
convert var cr=$ ("#cr") using the Get (index) method. Get (0);
3.DOM object to jquery object:
var Cr=document.getelementsbyid ("Cr"); Get DOM Object
var $cr =$ (CR);//Convert to jquery object