jquery Learning Notes Dom objects and jquery object _jquery

Source: Internet
Author: User
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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.