Why return this.each(function()) in jQuery plugins?

后端 未结 5 2092
感情败类
感情败类 2020-12-01 02:00

Some of the tutorials and examples I have seen for developing jQuery plugins tend to return

this.each(function () {
    //Plugin code here
});
5条回答
  •  日久生厌
    2020-12-01 02:27

    When you filter elements with a selector ($('.myclass')), it can match more than only one element.
    With each, you iterate over all matched elements and your code is applied to all of them.

提交回复
热议问题