Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I appendTo in JQuery, but have it fade in rather than instantly appear?

Specifically, I have a JQuery template, and I am using .tmpl to append it to a div. My code is:

$("#" + this.templateID).tmpl({ results: resultsArray }).appendTo("#" + this.targetID);

This whacks my template at the end of the div. However, I want to fade it in. I don't want to create an extra div on the page.

Ideally what I'd like to do is add the templated data to the page, and select the outermost element and set it to display none so it appears invisibly. Then tell it to fade in, so the resulting markup matches the other items already on the page seamlessly.

Any ideas how to do this?

like image 607
NibblyPig Avatar asked Jan 20 '23 13:01

NibblyPig


1 Answers

Add first .hide() to it and the use .fadeIn() after appending it.

Thus:

$("#" + this.templateID)
    .tmpl({ results: resultsArray })
    .hide()
    .appendTo("#" + this.targetID)
    .fadeIn();
like image 166
jerone Avatar answered May 17 '23 13:05

jerone