Created
April 30, 2011 07:01
-
-
Save ryansukale/949494 to your computer and use it in GitHub Desktop.
Creating a cross browser max-width value using jQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*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