i have a div, div1 with a height according to the text, div2 is the same. Now i need div3 to be: div1 + div2
I have this code, but it ain’t workin.
var lengthnews1 = ((document.getElementById("div1").offsetHeight)+"px");
var lengthnews2 = ((document.getElementById("div2").offsetHeight)+"px");
var x = document.getElementById("div3");
x.height = (lengthnews1 + lengthnews2);
you are trying to add two strings, not numbers. Fetch both heights, add them and then add the “px” :
You can verify the working code at this fiddle