I have created a loop that templates my data and then appends it into a selected div, I want to make sure that this data has been completely templated and injected before I run my next function so what I really need is something like a callback function. Can anyone advise how I might do this?
JS
// Template slideshow
for (var i = 0, len = data.films.length; i < len; i++) {
var dataPath = data.films[i];
var tmp = '<li><img src="http://dummyimage.com/300/000/' + dataPath.id + '" /><h2>' + dataPath.title + '</h2></li>';
$('.slides').append(tmp);
}
// Want to run this once Im sure all data has been templated and injected
$('.flexslider').flexslider({
animation: "slide"
});
You don’t need a callback. The code that you have created is always injected by the time the loop completes.