.square {
width: 200px;
height: 100px;
background: orange;
transition: 800ms;
border: 1px solid green;
}
<body style="background: darkgoldenrod;">
<button>hello</button>
var rule1 = document.styleSheets[0].cssRules[0];
let fast_value;
/* ************************************************************************* */
/* allow units for transitionDuration for .square class this is "ms" and "s" */
/* ************************************************************************* */
if(rule1.selectorText == '.square') {
if(rule1.style.transitionDuration.substring(rule1.style.transitionDuration.length-2, rule1.style.transitionDuration.length) == 'ms') {
fast_value = (rule1.style.transitionDuration.substring(0, rule1.style.transitionDuration.length-2)|0); // probably only number of type integer (convert)
} else if(rule1.style.transitionDuration.substring(rule1.style.transitionDuration.length-1, rule1.style.transitionDuration.length) == 's') {
fast_value = Number(rule1.style.transitionDuration.substring(0, rule1.style.transitionDuration.length-1))*1000;
}
} else {
fast_value = 500;
}
function cqq(Q) {
var interval1 = setInterval( function() {
if(Q.length == 0){
clearInterval(interval1);
} else {
Q[0]();
Q.splice(0,1);
}
}, (fast_value)*2);
}
function a() {
document.getElementsByClassName('square')[0].remove();
}
function transition_a() {
let created_div2 = document.getElementsByClassName('square');
created_div2[0].style.background = 'green';
created_div2[0].style.height = 0;
created_div2[0].style.transform = 'rotate(90deg)';
}
var Q=new Array();
function b() {
Q.push(transition_a);
Q.push(a);
const new_div = document.createElement('div');
new_div.className = 'square';
new_div.textContent = 'hello';
document.body.appendChild(new_div);
if(Q.length == 2) { // const ? = 2
cqq(Q);
}
}
document.querySelector('button').onclick = b;
</body>
link link