IE jQuery returns auto instead of the element width
I am using jQuery to try an开发者_如何学Pythond get the width of an element that doesn't have the width set. In firefox it works fine, but in IE it returns AUTO instead of the actual width of the element.
jQuery('.nav-2').css('width');
Does anyone know of a work around or another way to get the width of the element that will work in IE?
Call .width()
instead.
You don't want the CSS width as the style is probably actually set to "auto". You want the actual object width which is obtained in jQuery with this:
jQuery('.nav-2').width();
Keep in mind that when obtaining the width using a selector that can return multiple elements, jQuery will return the width of the first matched element.
Get the total width (padding + width + borders + margin)
jQuery('.nav-2').outerWidth(true);
Remove 'true' to exclude margins
精彩评论