Skip to content

Instantly share code, notes, and snippets.

@sarfraznawaz2005
Last active October 12, 2015 18:30
Show Gist options
  • Select an option

  • Save sarfraznawaz2005/83891289636c21aed95e to your computer and use it in GitHub Desktop.

Select an option

Save sarfraznawaz2005/83891289636c21aed95e to your computer and use it in GitHub Desktop.
Add callback to jQuery's CSS method
// Allows you to pass a function to jQuery's 'css' method
// This means you can use the -this- keyword to reference
// the current element!!!
(function($){
$.fn.oldCSSMethod = $.fn.css;
$.fn.css = function(o) {
return $.isFunction(o) ?
$(this).each(function(){
$(this).oldCSSMethod(o.call(this));
})
: $(this).oldCSSMethod.apply($(this), arguments);
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment