jquery objects are not DOM objects

Source: Internet
Author: User

jquery objects and Dom objects convert fonts to each other: [Increase decrease] Type: Reprint jquery object is the object that is produced 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, such as $ ("#img"). attr ("src", "test.jpg"); The $ ("#img") here is the jquery object;

Dom objects are some of the inherent object operations of JavaScript. Dom objects can use JavaScript's inherent methods, but cannot use the methods in jquery. For example: document.getElementById ("img"). src= "Test.jpg"; here the document.getElementById ("img") is the DOM object;
$ ("#img"). attr ("src", "test.jpg"); and document.getElementById ("img"). src= "Test.jpg"; is equivalent, is correct, but $ ("#img"). src= "Test.jpg" or document.getElementById ("img"). attr ("src", "test.jpg"); are all wrong.

In an example: this is what I often write about 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, such as $ (this). attr ("src", "test.jpg");

The 1.DOM object is converted to a jquery object:

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

such as: Var V=document.getelementbyid ("V"); Dom Object

var $v =$ (v); jquery Object

After the conversion, you can use the JQuery method arbitrarily.

The 2.jQuery object is turned 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].

such as: 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

such as: Var $v =$ ("#v"); jquery Object

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

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

jquery objects are not 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.