jquery puzzle-Wrapper set DOM node _jquery

Source: Internet
Author: User
Tags wrapper
$ (' #someElement ') and $ (' #someElement ') [0], this statement brings me a period of confusion, at the beginning of each use I always in one of the wrong time to replace the other one,
Although every time to complete the function, but there are always in the depressed! Then finally understand the reason: $ (' #someElement ') although only select elements, but it is still a wrapper set,
Methods of DOM nodes (such as setattribute, etc.) cannot be used. and $ (' #someElement ') [0] is really the first element that returns the wrapper set, all of which can use the DOM node's method.

All in all: When using jquery, you need to be aware of the difference between a wrapper set and a DOM node, and jquery provides a way to wrap a set and not use the JQuery method on a DOM node.
Similarly, a DOM node's method cannot be used on a wrapper set, and can only be applied to a DOM node. Of course, there are attributes (such as innerHTML) in addition to the method.
I can also wrap a DOM node in a wrapper set: We often use $ (this) to wrap a node in a wrapper set and then process it using the jquery method.

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.