Home > Web Front-end > JS Tutorial > body text

JQuery Confusion—Wrapper Set DOM Node_jquery

WBOY
Release: 2016-05-16 18:44:27
Original
870 people have browsed it

$('#someElement') and $('#someElement')[0], this statement caused me confusion for a while. At the beginning, every time I used it, I always replaced one with the other when an error occurred.
Although the function can be completed every time, it is always unspeakably frustrating! Later, I finally understood the reason: although $('#someElement') only selects elements, it is still a packaging set, and
cannot use DOM node methods (such as SetAttribute, etc.). And $('#someElement')[0] does return the first element in the packaging set, all methods it can use DOM nodes.

In short: When using JQuery, you need to pay attention to the difference between wrapper sets and DOM nodes. The methods provided by JQuery are all wrapper set methods. You cannot use JQuery methods on DOM nodes.
Similarly, DOM nodes Methods also cannot be used on wrapper sets, 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 also wrap DOM nodes into wrapper sets: For example, we often use $(this) to wrap the nodes into wrapper sets and then use JQuery methods to process them.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!