jquery Gets the difference between the HTML element and the document gets the element

Source: Internet
Author: User

Recently through the OCX made a video plugin, and then put the plugin into the HTML (want to know can see)

Because I want to operate this plugin, to play, stop and so on, so I need to get this element, no accident, I use jquery to get, and then simply can not execute, and then use the document to get, normal execution, as follows

// Normal execution      var obj = document.getElementById ("player00"); Obj.testhelloworld (); // cannot execute var playobj = $ (' #player00 ');p Layobj.testhelloworld ();

And I was thinking, what's the difference between the two? And then search for the following conclusions

jquery gets an HTML element that is a jquery object that can execute the jquery method, while document gets the DOM object and executes the DOM method

Immediately relieved, I have always thought that the two are equivalent, and in order to investigate why the DOM method can not be implemented in jquery, now think about, completely relieved.

In that case, how do they convert each other? After all, the content of the obtained object is the same.

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].
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

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. $ (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.
With the above methods, jquery objects and Dom objects can be converted to each other arbitrarily. It is important to note that DOM objects can use methods in the DOM, and jquery objects are not available in the DOM.

jquery Gets the difference between the HTML element and the document gets the element

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.