$('elems').each() with fat arrow

故事扮演 提交于 2019-11-27 09:13:39

The each() method supplies two parameters to the callback-function. They are current index and the current item. Thus you could do the following:

$('ul#mylist > li').each((i, v) => {
   $(v).addClass('some-class-name');
});

Where the "v" variable is the current "li" element

Because this in the arrow function context is the same as the calling context.

The each function provides a current element as the second argument to the callback so

$('ul#mylist > li').each((i, el) => {
  $(el).addClass('some-class-name');
});

Or in the given case there is no need to loop

$('ul#mylist > li').addClass('some-class-name');
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!