JQuery confusions-wrap set DOM nodes

Source: Internet
Author: User

$ ('# SomeElement') and $ ('# someElement') [0]. This statement has puzzled me for a period of time, at the beginning, I always change one of them to another when an error occurs,
Although the function can be completed every time, it is always hard to say! Later, I finally understood the principle: $ ('# someElement'), although only elements are selected, it is still a package set,
You cannot use DOM node methods (such as SetAttribute ). $ ('# SomeElement') [0] returns the first element in the wrapper set. All methods that can use DOM nodes are returned.

In short: when using JQuery, pay attention to the differences between the packaging set and the DOM node. The methods provided by JQuery are the method of the packaging set, and the JQuery method cannot be used on the DOM node,
Similarly, the DOM node method cannot be used in the packaging set, but can only be applied to DOM nodes. Of course, in addition to methods, there are also attributes (such as innerHTML ).
At the same time, I can package DOM nodes into packaging sets. For example, we often use $ (this) to package nodes into packaging sets and then use JQuery to process them.

Related Article

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.