I am trying to insert an element using the "insertAfter" method and then add a class to trigger a CSS animation.
It seems to work when I use a timeout function:
First Approach (with Timeout)
$content.insertAfter($("#2"));
setTimeout(function(){
$content.addClass("blue");
}, 100);
However, it does not work when I try to add the class directly after inserting the element:
Second Approach (without Timeout)
$content.insertAfter($("#2")).addClass("blue");
Is there another solution that does not involve using a timeout function?
You can view my code in this fiddle: http://jsfiddle.net/b2eybnoy/