Skip to content

Instantly share code, notes, and snippets.

@ryansukale
Created April 30, 2011 07:01
Show Gist options
  • Save ryansukale/949494 to your computer and use it in GitHub Desktop.
Save ryansukale/949494 to your computer and use it in GitHub Desktop.
Creating a cross browser max-width value using jQuery
/*Sample code to calculate the max-width of an element via jquery that can be applied to all browsers*/
/*Append the element to the body/anywhere else you want to append the element to, in order to allow the browser to render the initial width of the element*/
var $element = ('<div></div>');
$('body').append($element);
if($element.width()>someWidth){
/*since the max-width property does not work in IE,
we set the max width by comparison after the element is added to the dom*/
$element.css({'width':someWidth});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment