jQuery .each() returns DOM element and not a jQuery object

后端 未结 2 1210
礼貌的吻别
礼貌的吻别 2021-02-02 07:33

I could be misunderstanding what is happening but from what I can tell I am getting a DOM element and not a jQuery object when I use .each().

The below will

2条回答
  •  感动是毒
    2021-02-02 08:03

    The documention is not wrong but you may misunderstand what a jQuery object is.

    The jQuery object is returned by the $() function. So $("span[id$='_TotalItemCost']") is one jQuery object which contains every span element selected.

    Using .each() will iterate over the elements contained in the jQuery object. This is why this is a DOM node and not a jQuery object.

    You did the right thing by using $(this) to use the jQuery methods on this specific element.

提交回复
热议问题