I'm trying to add a method to a jQuery object that has the same name (but different parameter set) as another method.
What I've got so far:
jQuery.fn.insertBefore = function(elem, duration)
{
this.css("display", "none");
this.insertBefore(elem);
this.toggle(duration);
}
However, this code (specifically the this.insertBefore(where); line) calls this same function, and not the jQuery insertBefore() function, as desired. What do I need to do in order to add this function to the jQuery object, and have it overload (not overwrite) the existing 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);