Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

7
  • 2
    If I recalled correctly, jQuery has pulled much of dimensions into the core. Do you still need dimensions to do what you're suggesting?
    – Nosredna
    Commented Jun 24, 2009 at 14:41
  • 6
    The $(window).width() support in jQuery is since version 1.2, in case it's relevant to anybody.
    – chaos
    Commented Jun 24, 2009 at 14:44
  • 20
    I've found that $(window).width() does not always return the same value as innerWidth / clientWidth as per the examples in the answer below. jQuery's version doesn't take browser scrollbars into account (in FF anyway). This caused me a lot of confusion with CSS @media queries appearing to trigger at the wrong width. Using native code seems to be more reliable as it takes the appearance of the scrollbars into account.
    – Coder
    Commented Jan 19, 2013 at 10:17
  • 13
    Adding 30k lines of code to get window width is a BAD solution!
    – codechimp
    Commented Feb 7, 2018 at 16:34
  • 2
    @codechimp "Adding 30k lines of code to get window width is a BAD solution!" Proceeds to add a 80k file just to get window width. Bad is relative.
    – Madness
    Commented Feb 8, 2018 at 21:45