Skip to content

Latest commit

 

History

History
83 lines (66 loc) · 3.07 KB

File metadata and controls

83 lines (66 loc) · 3.07 KB

jQuery

jQuery.fn.init
jQuery.fn = jQuery.prototype

jQuery.fn.jquery // Find version

You don't need jQuery

Plugins and Libraries

git checkout tags/2.0.3
$.fn.plugin.defaults.something = false;

$.fn.plugin = function(options) {
  var settings = $.extend({}, $.fn.plugin.defaults, options);
  
  // You can use `this` inside here which refer to
  // jQuery object
  
  // For you loop, you need to use `$(this)`
  return this.each(function() {
    $(this).xxx
  });
  
  // If you have callback, it is better to use `call`
  // and pass in the desired object for `this`
  settings.onChange.call(this)
}

Some examples of plugin

;(function($) {
  $.fn.removeWhitespace = function() {
    this.contents().filter(function() {
      return (this.nodeType === 3 && !/\S/.test(this.nodeValue))
    }).remove();
    return this;
  };
})(jQuery);

History