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

后端 未结 2 1877
灰色年华
灰色年华 2020-12-01 21:08

I started to use ES6 fat arrow function notation and I really like it. But I am a little bit confused about it context. As far as I know, keyword this inside fat arrow funct

2条回答
  •  无人及你
    2020-12-01 21:34

    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

提交回复
热议问题