Conversion Between Dom and jquery Based on jquery

Source: Internet
Author: User

Introduction:
Jquery object: The object generated after DOM object is encapsulated by jquery.
DOM objects cannot use jquery object methods. Similarly, jquery objects cannot use DOM object methods.
Example ::
$ ("# Foo" ).html (); // This is the use of jquery objects
Its functions are equivalent:
Document. getelementbyid ("foo"). innerhtml; // method of the DOM object
1. convert a jquery object to a DOM object
Method 1:
VaR $ text = $ ("# text"); // obtain the element with the ID Cr on the page and return the jquery object.
VaR text = $ text [0]; // convert a jquery object to a DOM object
Method 2: (use the get () method)
VaR $ text = $ ("# text ");
VaR text = $ text. Get (0 );
2. convert a DOM object to a jquery object
VaR text = Document. getelementbyid ("text"); // DOM object
VaR $ text = $ (text); // convert to jquery object
Iii. Instances
HTML:
<Input type = "checkbox" id = "text"/> <label for = "text"> I have read the above rules </label>
JS:
Use Dom to check whether checkbox is selected:
$ (Document). Ready (function (){
VaR $ text = $ ("# text"); // jquery object
VaR text = $ text. Get (0); // DOM object
$ Text. Click (function (){
If (text. Checked ){
Alert ("thank you for your support! ");
}
})
});
Use jquery to check whether checkbox is selected:
$ (Document). Ready (function (){
VaR $ text = $ ("# text ");
$ Text. Click (function (){
If ($ text. Is (": checked") {// use $. Is () of the jquery object to determine
Alert ("thank you for your support ");
}
})
});

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.