What is the major difference between $(window).width() vs $(document).width() in jQuery? Whether window denotes the browser and document represents
$(window).width()
$(document).width()
Another important difference.
$(window).width(); is available before the document loads / is ready
$(window).width();
$(document).width(); is only available after the document had loaded
$(document).width();
So for the second, you need
$(document).ready(function() { var w = $(document).width(); });