jquery objects and JavaScript objects that are DOM objects are converted to each other

Source: Internet
Author: User

jquery objects and JavaScript objects that are DOM objects are converted to each other

1. DOM object into JQuery object
For a DOM object, you just need to wrap the DOM object with $ () and you can get a JQuery object, $ (DOM object) Note: VAR is a variable defined
Such as:

var v = document.getElementById ("V"); /dom object
var $v = $ (v);//jquery Object
After conversion, you can use JQuery in any way.
2. JQuery objects into DOM objects
Two ways to convert a jQuery Objects into DOM objects: [index] and. get (index);
(1) The JQuery object is a data object that can be used by the [index] method, To get the corresponding DOM object.

var $v = $ ("#v");//jquery Object
var v = $v [0] ; DOM object
alert ( v.checked); Detects whether the checkbox is selected
(2) The jQuery itself is provided by the. Get (index) method to get the corresponding DOM object
example:

var $v = $ ("#v"); JQuery Object
var v = $v. Get (0); Dom Object ($v. get () [0] can also)
alert (v.checked); Detects if the checkbox is selected

jquery objects and JavaScript objects that are DOM objects are converted to each other

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.