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 ");
}
})
});