JQuery - determine if the height of an element is greater than the height of the window and do something

In fact, everything says.

Basically, I want to determine if this is div heightmore more window heightand have something to do with it.

I did this, but I can't get it to work http://jsfiddle.net/dhkCa/3 Why doesn't it work?

Edit: Fixed a small bug in the css code. Updated Jsfiddle link.

+5
source share
2 answers

document , ( display:block ); . window, :

var div = $("div").height();
var win = $(window).height();

if (div > win ) {
    $("div").addClass('red');
}

JS Fiddle demo.

+17

, , element.getBoundingClientRect().height (Docs).

0

All Articles