I have an array with predefined strings:
var linesArr = ["asd", "dsa", "das"];
I have a div that I created using JS and styled it using my CSS:
var div = document.createElement("div"); div.className = "storyArea"; div.innerHTML = linesArr[0];
Right now I have this code that can animate fadeIns and fadeOuts texts when clicked:
$(div).click(function(){ $(this).fadeOut(1000, function() { $(this).text("Random text").fadeIn(2000); }); });
But this is not a loop that can go through my array elements, it will show predefined text all the time.
I tried to write a loop that can work through this, but got lost:
$(div).click(function(){ for (var i = 1; i < linesArr.length; i++) { $(div).fadeOut(1000, function() { $(this).html(linesArr[i].fadeIn(2000)); }); }; });
This loop does not work, I have no console errors, but the logic here is wrong. Can someone help me?
source share