Conversion between jQuery objects and dom objects

Source: Internet
Author: User
I have never understood some methods for directly using JavaScript For objects obtained through jQuery. Now I know about this case, the objects obtained by jQuery are not the same as those obtained by getElementById. So some new users... SyntaxHighlighter. all

I have never understood some methods for directly using JavaScript For objects obtained through jQuery. Now I know about this case, the objects obtained by jQuery are not the same as those obtained by getElementById. Therefore, some new users are confused about why $ {"# Element"} cannot be directly innerHTML. This is the reason. For the solution, see the following.

Conversion between jQuery objects and dom objects
Only jquery objects can use methods defined by jquery. Pay attention to the differences between dom objects and jquery objects. When calling methods, pay attention to dom objects or jquery objects.
Common dom objects can be converted to jquery objects through $.

For example:

$ (Document. getElementById ("msg "))
This is a jquery object. You can use the jquery method.
Because the jquery object itself is a set. Therefore, if a jquery object is to be converted to a dom object, You must retrieve one of them. Generally, you can retrieve it through indexes.
For example:
$ ("# Msg") [0], $ ("div "). eq (1) [0], $ ("div "). get () [1], $ ("td") [5]

These are dom objects. You can use methods in dom, but you cannot use Jquery methods.
The following statements are correct:
$ ("# Msg" cmd.html ();
$ ("# Msg") [0]. innerHTML;
$ ("# Msg"). eq (0) [0]. innerHTML;
$ ("# Msg"). get (0). innerHTML;
 

From Zhang Yi ☆. Net★Java software alliance

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.