what does “return this.each()” do in jQuery?

后端 未结 5 991
轮回少年
轮回少年 2021-02-08 21:25

I\'m looking at a jQuery plugin, which has a single function. After setting up the appropriate defaults though a constructor argument the function defines a couple of helper fu

5条回答
  •  一生所求
    2021-02-08 21:44

    .each returns the elements it was called on, so in this case, it is probably to maintain the ability of methods to be chained on that selector. That means that if the plugin'S method is called foo, you should be able to do

    $("mySelector").foo().show();
    

    Because foo returned the result of .each which is basically $("mySelector").

    Hope that made sense.

提交回复
热议问题