Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Subtracting from div height in jQuery

today I have a quick question. Here is my function:

function checkheight() {
var heightofdiv = $('#checkforheight').height();
$("#centeredbackground").css("min-height",heightofdiv);
}

My problem is that I want to get my variable, heightofdiv, and then subtract the answer by 42 pixels. So really, I want heightofdiv to be equal to the height of checkforheight minus 42 pixels. If this is even possible, help would be greatly appreciated. Thanks!

like image 356
Eggo Avatar asked Feb 29 '12 22:02

Eggo


2 Answers

Can you not simply subtract 42 from $('#checkforheight').height()?

var heightofdiv = $('#checkforheight').height() - 42;
like image 176
Colin Brock Avatar answered Sep 18 '22 01:09

Colin Brock


What's stopping you from just doing this?

$('#checkforheight').height() - 42;
like image 22
Justice Erolin Avatar answered Sep 21 '22 01:09

Justice Erolin