If a div is set as overflow:auto
, how can I find out (using plain JS) if a scrollbar (Vertical / Horizontal) has been rendered?
To check if a scrollbar is present for an element, we can compare the scrollHeight value with its clientHeight value, both are in pixels.
Many assume that width: 100vw is the same as width: 100% . This is true on a page that doesn't scroll vertically, but what you might not realize is that the viewport actually includes the scrollbars, too.
Show scroll bars in Word and Excel for WindowsClick File > Options. On the Advanced tab, scroll to the Display section. Select Show horizontal scroll bar and Show vertical scroll bar, and then click OK.
Check if clientHeight is smaller than scrollHeight.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With