Reputation: 63
I need to change the height of the footer by finding out the height of another div.
I'm using the .css("height")
function, but I can't get the function to return the answer in pixels.
Here's the code I'm using. It's returning NaN
.
if($("#middleContainer").height() > 500){
var add_height = $("#middleContainer").css("height") - 500;
alert(add_height);
}
After looking at the suggestions, I'm using the following code. It doesn't make any difference.
if($("#middleContainer").height() > 500){
var add_height = $("#middleContainer").height() - 500;
var new_height = -850 + add_height;
alert(new_height);
$(".footer").css("top", "new_height");
}
Upvotes: 2
Views: 4732
Reputation: 18600
Following code return height with string type so you have to parse as Int
var add_height = parseInt($("#middleContainer").css("height")) - 500;
// Return as String data type value
This code return number so do not want to parse as Int it directly works
var add_height = $("#middleContainer").height();
// Return as Number data type value
Upvotes: 2
Reputation: 884
The answer is always in pixeis, you just need to parse it
var h =$(something).height() - 500;
$('something').height(h);
Upvotes: 0