I am working on a code to create a "fade-In fade-Out" effect for text. However, I'm facing an issue where the text displayed is always the last value in the array instead of changing to the next one each time it fades in and out.
Here is the HTML code below:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
<script>
$(document).ready(function(){
var str = $("#string").text().split(' + ');
setInterval(function(){
s++;
for (var s = 0; s < str.length; s++) {
var string = str[s];
$("#string").html(string);
$("#string").fadeIn(500);
$("#string").fadeOut(3000);
}
}, 6000);
});
</script>
</head>
<body>
<p id="string" style="display:none;">Name 1 - Message 1 + Name 2 - Message 2 + Name 3 - Message 3</p>
</body>
</html>
Thank you!