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

后端 未结 5 2095
感情败类
感情败类 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:20

    jQuery supports "chainable methods", which means that most jQuery functions should return this. .each() returns this, and if you want $('selector').yourPlugin().css(...) to work, you should return this.

提交回复
热议问题