Mutual conversion between jquery objects and DOM objects

Source: Internet
Author: User

The conversion between jquery objects and DOM objects is a common problem in the process of actually writing code. for the research on this problem, we can first agree on the variable style: if the obtained object is a jquery object, add $. as follows: [javascript] var $ variable = jquery object if the obtained object is a DOM object, it is defined as follows: [javascript] var variable = DOM object the following describes how jquery and DOM objects are converted: 1. convert a jquery object to a DOM object: jquery objects cannot use methods in the DOM, but if they are unfamiliar with the methods provided by the jquery object, or jquery does not encapsulate the desired method, when you have to use a DOM object, there are two methods: (1) the jquery object is an array-like object. You can use the [index] method to obtain the corresponding DOM object. The Code is as follows: [javascript] var $ axin =$ ("# Axin "); // jquery object var axin = $ axin [0]; // DOM object (2) get the corresponding DOM object through the get (index) method provided by jquery itself: the Code is as follows: [javascript] var $ axin =$ ("# axin"); // jquery object var axin = $ axin. get (0); // DOM object 2. to convert a DOM object to a jquery object, you only need to wrap the DOM object with $ (). The Code is as follows: [javascript] var axin = document. getElementById ("axin"); // DOM object var $ axin = $ (axin); // note that only DOM can use methods in DOM, jquery objects cannot use methods in 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.