My goal is to create a div and then transition it to it's correct position.
// the HTML comes from a source, can't change this
var TheHTML = "<div id=\"abc\"></div>";
// HTML to Element
var TempDiv = document.createElement('div');
TempDiv.innerHTML = TheHTML;
var TheNewElement = TempDiv.firstChild;
// adding the new element
document.getElementById("container").appendChild(TheNewElement);
// adding transitions and style
document.getElementById("abc").style.transition = "left 1s, width 1s";
document.getElementById("abc").style.left = "100px";
document.getElementById("abc").style.width = "100px";
This does not work, it just spawns without any animated transition. However, if I add a small delay after appending the div, it works. Example:
// the HTML comes from a source, can't change this
var TheHTML = "<div id=\"abc\"></div>";
// HTML to Element
var TempDiv = document.createElement('div');
TempDiv.innerHTML = TheHTML;
var TheNewElement = TempDiv.firstChild;
// adding the new element
document.getElementById("container").appendChild(TheNewElement);
// break for short pause
alert("break");
// adding transitions and style
document.getElementById("abc").style.transition = "left 1s, width 1s";
document.getElementById("abc").style.left = "100px";
document.getElementById("abc").style.width = "100px";
I would prefer a solution where I don't need to wait for some timer, but it would be okay to wait for the appending to finish if that's an option and not some hard-coded timer.