Subtract 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 42 pixel response. So really, I want the heightofdiv to be equal to the height of the control light minus 42 pixels. If even possible, help would be greatly appreciated. Thanks!

+4
source share
3 answers

Can't you just subtract 42 from $('#checkforheight').height() ?

 var heightofdiv = $('#checkforheight').height() - 42; 
+5
source

What is stopping you from just doing this?

 $('#checkforheight').height() - 42; 
+1
source

This should help you find what you are looking for.

$ ("# centeredbackground"). css ("min-height", (heightofdiv - 42));

+1
source

Source: https://habr.com/ru/post/1399099/


All Articles