7wp 7wp - 1 year ago 65
Javascript Question

Detecting presence of a scroll bar in a DIV using jQuery?

I want to detect the presence of a scroll bar in a DIV using jQuery. I was thinking to use

but that returns 0 in both cases when the scroll bar is at the top and when there is no scroll bar at all.

Any ideas guys?

Answer Source

Assuming overflow on the div is auto:

var div= document.getElementById('something'); // need real DOM Node, not jQuery wrapper
var hasVerticalScrollbar= div.scrollHeight>div.clientHeight;
var hasHorizontalScrollbar= div.scrollWidth>div.clientWidth;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download