Difference between jQuery.extend and jQuery.fn.extend?

前端 未结 5 728
醉话见心
醉话见心 2020-11-27 09:57

I am trying to understand the jquery plugin syntax, because I want to merge two plugins into one. The blinker that also needs to be able to stop de interval or run a number

5条回答
  •  盖世英雄少女心
    2020-11-27 10:24

    jQuery.extend({
        abc: function(){
            alert('abc');
        }
    });
    

    usage: $.abc(). (No selector required like $.ajax().)

    jQuery.fn.extend({
        xyz: function(){
            alert('xyz');
        }
    });
    

    usage: $('.selector').xyz(). (Selector required like $('#button').click().)

    Mainly it is used to implement $.fn.each().

    I hope it helps.

提交回复
热议问题