You're missing +"px"
. You are required to set a unit (em
, px
, %
, etc) when using style.height
. Because scrollHeight
gives you just a numeric value, you must append the units which are px
in this case.
function expandContract(id) {
var object = document.getElementById(id);
if (object.style.height != "0px") {
object.style.height = "0px";
} else {
object.style.height = object.scrollHeight+"px";
}
}