Instance code for converting between jquery objects and JavaScript objects _jquery

Source: Internet
Author: User

Copy Code code as follows:

Here are some of my share, I love programming, hope to be able to pay more programming enthusiasts, if you are also one of them, then please add friends, we pay attention to, the following article is that they feel some useful things, stay to yourself as a note, of course, also hope to help you, first of all thank you for your reading ~!
If we use jquery as a script for the client page, we often refer to the mutual conversion of jquery objects and JavaScript objects. Because DOM objects are some object operations that are intrinsic to JavaScript. DOM objects can use the intrinsic methods of JavaScript, but they cannot use the methods in JQuery. Therefore, we in Guangzhou the share a little bit between their conversion code for everyone to learn and reference.

1. DOM objects Turn into JQuery objects

For a DOM object, you can get a JQuery object by wrapping the DOM object with $ (), $ (DOM object)

such as: var v = document.getElementById ("V"); Dom Object

var $v = $ (v); JQuery objects

After conversion, you can use the JQuery method as you like.

2. JQuery objects Turn into DOM objects

Two conversions speak of a JQuery object converted to a DOM object: [index] and. get (index);

(1) The JQuery object is a data object, which can be obtained through the method of [index] to get the corresponding DOM object.

such as: var $v = $ ("#v"); JQuery objects

var v = $v [0]; DOM Object

alert (v.checked); Detect if this checkbox is selected

(2) JQuery itself provides the corresponding DOM object through the. Get (Index) method

such as: var $v = $ ("#v"); JQuery objects

var v = $v. Get (0); Dom objects ($v. get () [0] can also)

alert (v.checked); Detect if this checkbox is selected

Related Article

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.