I am prepending some data to my page on a button click and instead of just populating immediately on the page, I was wondering if there is a way to animate the prepend()
using slideToggle
or CSS animation.
Here is my current script:
var data = $('.data').html();
var insert = '<div class="data-container">'+ data +'</div>';
$('button').click(function(){
$('.data-container').remove();
$('.initial').prepend(insert);
});
and a JSFiddle
This one liner works great for me, even without the clone()
I'm using it like so:
var elementToPrepend = "<div>Your content</div>";
$(elementToPrepend).hide().prependTo(".prependHere").fadeIn();
Edit: Proper one-liner would be:
$("<div>Your content</div>").hide().prependTo(".prependHere").fadeIn();