Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created June 29, 2011 18:54
Show Gist options
  • Save chucktrukk/1054594 to your computer and use it in GitHub Desktop.
Save chucktrukk/1054594 to your computer and use it in GitHub Desktop.
$('label').autoWidth({limitWidth: 350});
jQuery.fn.autoWidth = function(options)
{
var settings = {
limitWidth : false
}
if(options) {
jQuery.extend(settings, options);
};
var maxWidth = 0;
this.each(function(){
if ($(this).width() > maxWidth){
if(settings.limitWidth && maxWidth >= settings.limitWidth) {
maxWidth = settings.limitWidth;
} else {
maxWidth = $(this).width();
}
}
});
this.width(maxWidth);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment