If a div is set as overflow:auto
, how can I find out (using plain JS) if a scrollbar (Vertical / Horizontal) has been rendered?
Asked
Active
Viewed 2.7k times
39

KJ Saxena
- 21,452
- 24
- 81
- 109
1 Answers
65
Check if clientHeight is smaller than scrollHeight.
-
7Finding every element on page that has a scrollbar `[...document.querySelectorAll('*')].filter(x => x.clientHeight < x.scrollHeight)` – A1rPun Aug 27 '19 at 08:35
-
I tried this... `function isOverflown(element) { return element.scrollHeight > element.clientHeight; } function scroll_notification() { if(isOverflown(document.getElementById("myDiv"))) { // function content } }` but I get this error... ***TypeError: null is not an object (evaluating 'element.scrollHeight')*** – G-J Jun 29 '23 at 01:00