How can I make a function defined in jQuery.ready available globally?

后端 未结 6 1729
悲&欢浪女
悲&欢浪女 2020-12-04 08:17

I have a function that strips the youtube id off a url. I then want to use this function 10 time per page (in the wordpress loop).

The function works great when I fe

6条回答
  •  独厮守ぢ
    2020-12-04 08:38

    You can simply add your function in the $.fn variable:

    (function ($) {
    
       $.fn.getList = function() {
           // ...
       };
    
    }(jQuery));
    

    Example usage:

    $().getList();
    

    This is what you would typically do while creating a Basic Plugin for jQuery.

提交回复
热议问题