This should work
$.fn.hasVerticalScrollBar = function () { return this[0].clientHeight < this[0].scrollHeight; } $.fn.hasHorizontalScrollBar = function () { return this[0].clientWidth < this[0].scrollWidth; }
Using
alert($('#mydivid').hasHorizontalScrollBar()); alert($('#mydivid').hasVerticalScrollBar());
EDIT:
To use this method with an invisible element, clone the div, set its opacity to 0, add the clone to the body, check if the clone has a scroll bar, and then removes the clone:
var clone = $('#mydivid').clone(); clone.css('opacity', '0').appendTo('body'); if (clone.hasHorizontalScrollBar()) {
John hartsock
source share