I am trying to add a method to a jQuery object with the same name (but with a different set of parameters) as another method.
What I have so far:
jQuery.fn.insertBefore = function(elem, duration) { this.css("display", "none"); this.insertBefore(elem); this.toggle(duration); }
However, this code (in particular, the line this.insertBefore(where); ) calls the same function, not the jQuery insertBefore() function, at will. What do I need to do to add this function to the jQuery object and reload (not overwrite) the existing one function?
EDIT: solution
(function ($) { var oldInsertBefore = $.fn.insertBefore; jQuery.fn.insertBefore = function(elem, duration) { if (duration === undefined) { oldInsertBefore.call(this, elem); return; } this.css("display", "none"); this.insertBefore(elem); this.toggle(duration); } })(jQuery);
source share