The difference between a DOM object and a jquery object

Source: Internet
Author: User

1.DOM objects

The DOM is actually a document model that is described in an object-oriented manner. The DOM defines the objects that are required to represent and modify the document, the behavior and properties of those objects, and the relationships between those objects.

DOM is an application programming interface (API) for HTML and XML according to the DOM specification.

Through the DOM, you can access all of the HTML elements, along with the text and attributes they contain, to modify and delete the contents, and to create new elements.

The HTML Dom is independent of the platform and programming language and can be used by any programming language such as Java,javascript and VBScript.

Dom objects, which are the objects we get with traditional methods (JavaScript).

2.jQuery objects

The jquery object is actually an array of JavaScript, which contains 125 methods and 4 attributes;

The 4 attributes are:

jquery Current jquery Framework version number

Length indicates the number of elements of the array object

In general, the context is pointing to the HTMLDocument object

Selector passed in the selector content such as: #yourId或. YourClass, etc.

If you get the jquery object through the $ ("#yourId") method,

And there's only one element in your page with ID yourid.

Then $ ("#yourId") [0] is the htmlelement element

The same elements as the document.getElementById ("Yourid")

Simple to understand, is the object created by jquery

The jquery object is the object that is generated after wrapping the DOM object through jquery. jquery objects are unique to jquery and can be used in jquery, but cannot use the DOM method

The difference between a 3.DOM object and a jquery object

[JavaScript]

var domobj = document.getElementById ("id"); Dom Object

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

[JavaScript]

$ ("#img"). attr ("src", "test.jpg"); The $ ("#img") here is to get the jquery object

[JavaScript]

document.getElementById ("img"). src= "test.jpg";//Here

document.getElementById ("img") is the DOM object;

Another example: this, which I often write when I write jquery:

This.attr ("src", "test.jpg");

But it was a mistake. This is actually a DOM object, and. attr ("src", "test.jpg") is the jquery method, so something went wrong. To solve this problem, convert the DOM object to a jquery object, for example: $ (this). attr ("src", "test.jpg");

Conversion of 4.DOM objects and jquery objects

The DOM object is turned into a jquery object:

For a DOM object, you can just wrap the DOM object with $ () and you'll get a jquery object.

Method: $ (DOM object)

[JavaScript]

var V=document.getelementbyid ("V"); Dom Object

var $v =$ (v); jquery Object

The jquery object turns into a DOM object:

Two conversions convert a jquery object to a DOM object: [index] and. get (index);

(1) JQuery object is a data object, you can get the corresponding Dom object by means of [index].

[JavaScript]

var $v =$ ("#v"); jquery Object

var v= $v [0]; Dom Object

Alert (v.checked)//Detect if this checkbox is selected

(2) jquery itself provides, through the. Get (Index) method, to get the corresponding DOM object.

[JavaScript]

var $v =$ ("#v"); jquery Object

var v= $v. Get (0); Dom Object

Alert (v.checked)//Detect if this checkbox is selected

The Document Object model, or DOM, is the standard programming interface recommended by the Organization for the processing of extensible flag languages. On a Web page, objects that organize pages (or documents) are organized in a tree structure that represents the standard model for objects in a document called the DOM.

The Document Object model dates back to the late 1990 's "browser Wars" between Microsoft and Netscape, which gave the browser powerful features in order to make life and death in JavaScript and JScript. Microsoft has added a number of proprietary things to Web technology, including VBScript, ActiveX, and Microsoft's own DHTML format, making it impossible for many Web pages to be displayed using non-Microsoft platforms and browsers. Dom is the masterpiece of the time.

jquery is a set of cross-browser JavaScript libraries that simplifies the operation between HTML and JavaScript. The first version was released by John Resig on the January 2006 BarCamp NYC. It is currently being developed by the development team led by Dave Methvin. Of the top 10,000 most visited websites in the world, 59% use jquery, which is currently the most popular JavaScript library.

The difference between a DOM object and a 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.