I have used JQuery for front-end development for a period of time. It frees me from the pain of selecting elements to be operated, because the selection function is so powerful. At the same time, I have been confused by a problem for a long time during the development process. Maybe it is not a problem for others! $ ('# 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.
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.