Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When can $(document).width() and $(window).width() show different values?

Tags:

html

jquery

When can the values of the two differ?

like image 578
Rohan Avatar asked Jun 23 '26 10:06

Rohan


2 Answers

When you have a scrollbar on the webpage.

like image 158
samura Avatar answered Jun 25 '26 01:06

samura


Document.width will show the total width of the document.but window.width will return the current width of the window itself,if its been rezied.

$(window).width();   // returns width of browser viewport
$(document).width(); // returns width of HTML document

please check this link for more details.here

like image 32
Shambu Dev Avatar answered Jun 24 '26 23:06

Shambu Dev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!