Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jquery check if any parent div have scroll bar

I want to check if any parent div have scroll bar in jQuery but I can't find any good example. Here is my code:-

  <div>
     <div class="heading">
        <div class="visitor_profile">
            <div class="visitor_input_con">
            </div>
        </div>
    </div>
</div>

I want to check if any parent of .visitor_input_con has scroll bar here is my jquery code:-

(function($) {
  $.fn.hasScrollBar = function() {
    return this.get(0).scrollHeight > this.height();
  }
})(jQuery);

$('.visitor_input_con').hasScrollBar();

Please help me to solve this issue. Thanks

like image 207
user3819192 Avatar asked Jan 10 '15 10:01

user3819192


People also ask

How check scrollbar is present or not in jQuery?

$('#my_div1'). hasScrollBar(); // returns true if there's a `vertical` scrollbar, false otherwise..

How do I check if a scroll is present?

To check if a scrollbar is present for an element, we can compare the scrollHeight value with its clientHeight value, both are in pixels.


1 Answers

you could filter out parents, e.g:

if($('.visitor_input_con').parents().filter(function(){
    return $(this).hasScrollBar();
}).length)
like image 65
A. Wolff Avatar answered Oct 17 '22 20:10

A. Wolff