Reputation: 5418
I'm just curious as to what the difference between window.outerWidth
and $(window).outerWidth()
is, if any.
I couldn't really find much info about this on Google, so I thought I'd appeal to the masses. This is just a general question, not a specific issue.
Upvotes: 3
Views: 5682
Reputation: 664620
As you can read in the jQuery docs:
This method is not applicable to window and document objects; for these, use
.width()
instead.
While window.outerWidth
gets the width of the outside of the browser window, jQuery's .width()
method does return the width of browser viewport when called on a window
-selecting jQuery instance. To do this, it calls a bunch of subfunctionsand hooks (see source code) to be cross-browser-compatible (but is much slower).
Upvotes: 0
Reputation: 39532
As to the specifics of outerWidth
:
jQuery's implementation lets you choose if you want the margin included in the measurement or not. Javascript's just gets the number. I couldn't tell if it included margin or not.
jQuery is just a bunch of fancy JavaScript. In fact, you can implement anything jQuery does yourself using only JavaScript (and I'd encourage you to do so)! I'd encourage you to read questions like this one.
Upvotes: 0
Reputation: 3627
From jQuery documentation (http://api.jquery.com/outerWidth/):
This method is not applicable to window and document objects; for these, use .width() instead.
So, you should use $(window).width(), which returns:
"width of browser viewport" (so with no window borders and other stuff)
window.outerWidth returns whole window width (with borders and other stuff)
Upvotes: 2
Reputation: 8166
Returns the width of the element, along with left and right padding, border, and optionally margin, in pixels.
If includeMargin is omitted or false, the padding and border are included in the calculation; if true, the margin is also included.
This method is not applicable to window and document objects; for these, use .width() instead.
window.outerWidth gets the width of the outside of the browser window. It represents the width of the whole browser window including sidebar (if expanded), window chrome and window resizing borders/handles.
Upvotes: 6