Reputation: 23
i'm new to jquery
Here is what i want to achive, with jquery: if the div id 1 has a bigger height than the window height, set a class only to div id 1
<div id="1">some text</div>
<div id="2">some text</div>
<div id="3">some text</div>
Thank you
Upvotes: 1
Views: 437
Reputation: 70159
Here's a sample:
$(function() {
$(window).resize(function() { //whenever window is resized
var el = $('#1'); //caches the selector
if (el.height() > $(window).height()) //if #1.height > window.height
el.addClass('LargerThanWindow'); //add a class to it
else
el.removeClass('LargerThanWindow'); //else remove the class
}).resize(); //triggers the resize handler which we just set inside the
}); //DOM ready event
Fiddle
Resize the window vertically and you will see the class applied/removed.
Upvotes: 2