Search code examples
javascriptjqueryinternet-explorer

How can I get IE's width without scrollbar


I get the width of the browser using the following line:

$(document).width()

and then I set the element to this width.

But in IE, the horizontal scrollbar appears (width is larger than the browser size - I think this is because it counts the width of vertical scrollbar). I use the html 4.0 transition doctype. What should I do?


Solution

  • Try the clientWidth property, like so:

    $('body').attr('clientWidth')
    

    From the Mozilla Developer Center:

    clientWidth is the inner width of an element in pixels. It includes padding but not the vertical scrollbar (if present, if rendered), border or margin.

    From MSDN:

    Retrieves the width of the object including padding, but not including margin, border, or scroll bar.