Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created October 23, 2009 04:44
Show Gist options
  • Save paulirish/216655 to your computer and use it in GitHub Desktop.
Save paulirish/216655 to your computer and use it in GitHub Desktop.
// css() upgrade for a few shorthand values
// paul irish. MIT license.
// by default you can't do $(elem).css('margin'), but instead $(elem).css('marginTop') and so on.
// this monkeypatch allows lets you retrieve all four values in shorthand style:
// e.g. $(this).css('padding')
(function($){
var css = $.fn.css, methods = {'padding':1,'margin':1}, dirs = 'Top Right Bottom Left'.split(' ');
$.fn.css = function(prop,val){
var jq = this;
if ( val || !(prop in methods)) return css.apply(jq,arguments);
return $.map(dirs, function(k){ return css.call(jq,prop+k) }).join(' ');
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment