//cache the object in a variable var one = document.getElementById("one"); //do you really need to overwrite all stlyles defined on this object? //if not, prefer style-property over attribute //set animation-start one.style.height = 0; //force the browser to apply styles getComputedStyles(one); //apply the animation-target one.style.height = "200px";
You do not need a timeout, but be careful, this causes the browser to turn into a rendering cycle (one of the most expensive things that could be done in JS).
Therefore, do not use this in a loop (or on multiple nodes, one after the other). But instead, make two loops, first set all the initial values, force the browser into the rendering loop, and then apply all the target values.
source share