jquery Objects and Dom objects

Source: Internet
Author: User

JQueryis a terrific lightweightJavaScriptframework, in fact, inJQuerybefore it was released, there were countless more powerfulJavaScriptframework in Vogue. JQuerythe slogan is "write less, does more". (Selector,Domoperation,Jquery-ajax)

jquery is a terrific lightweight javascript frame , in fact, in jquery before publishing, There are countless more powerful javascript Framework in vogue. From the feature list, jquery in javascript frame can only be regarded as a very humble brother.

But this little brother in a short period of time, became the most popular javascript box One of the racks. Of course jquery There are many reasons for success, cross-, lightweight, not very poor performance, and jquery write less, do more

1.JQuery object and Dom object usage instructions

JQuery objects and Dom objects the first time you learn jquery, you often don't know which jquery objects are and which are DOM objects, so you need to focus on the jquery object and the DOM object and the relationships between them.

(i) DOM Object that's the object we get with traditional methods (JavaScript).

(ii) JQuery Object This is the object that is obtained with the jquery class library selector.

Copy the code code as follows:

var domobj =document.getelementbyid ("id");//dom Object

var $obj =$ ("#id");//jquery object;

JQuery object is the object that is generated after wrapping a DOM object through jquery , it is unique to jquery. If an object is a jquery object, you can use the method in jquery, for example:

$ ("#foo"). html ();// gets the HTML code within the element with the ID foo, and the HTML () is a unique method of jquery;

The code above is equivalent to:

document.getElementById ("foo"). InnerHTML;

Note: You cannot use any method of a DOM object in a jquery object.

For example $ ("#id"). InnerHTML and $ ("#id"). The checked and the like are all wrong. , you can replace it with a jquery method such as $ ("#id"). HTML () and $ ("#id"). attr ("checked").

Similarly, a DOM object cannot use the jquery method. Learning jquery starts with the right idea, distinguishing between jquery objects and Dom objects, and then learning jquery is a lot easier.

2.jQuery converting objects and DOM objects to each other

In the 1th above, jquery objects are not the same as DOM objects! For example, the jquery object cannot use the DOM method, the DOM object cannot use the JQuery method, and if I do not encapsulate the method I want, what can I do?

At this point we can convert the Jquer object to a DOM object

A. jquery object into DOM object

jquery provides two ways to convert a jquery object into a DOM object:

that is [index] and get (index) . Some people might find it strange, how to use subscript, yes, thejquery object is an array object .

The following code shows a way to convert a jquery object into a DOM object and then use the DOM object

Copy the code code as follows:

var $cr =$ ("#cr");//jquery Object

var cr = $CR [0];//dom objects can also be written as Var cr= $cr. Get (0);

alert (cr.checked);// detects if the checkbox is selected

B. Dom objects into jquery objects

For a DOM object, you simply wrap the DOM object with $ () and you can get a jquery object by $ (DOM object);

Copy the code code as follows:

Varcr=document.getelementbyid ("Cr");//dom Object

var $CR = $ (CR); Convert to jquery object

The method of jquery can be used arbitrarily after the conversion.

With the above methods, jquery objects and Dom objects can be converted to each other arbitrarily.

Finally, again, the DOM object can use the methods in the DOM, the jquery object cannot use the methods in the DOM, but the jquery object provides a more complete set of tools for manipulating the DOM, and the DOM operations on jquery are explained in detail later in the article.

The usual jquery objects are made by the $ () function, and the $ () function is a manufacturing facility for a jquery object.

Recommendation: If you get a jquery object, precede the variable with $, which makes it easy to identify what jquery objects are, such as:

var $variable = jquery object;

If you get a DOM object, it is defined as follows:

var variable = dom Object


Reference: The authoritative guide to jquery

jquery Objects and Dom objects

jquery Plugin

jquery Operation Ajax

jquery Animations and effects

jquery manipulating DOM Events

jquery Operation Dom

jquery Selector

jquery Preliminary






From for notes (Wiz)

jquery Objects and Dom objects

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.