Zup Stackoverflow!
I have a question regarding a problem I can’t seem to solve. I want to add text with a intervalfunction which should only be seen after the already existing text inside a h2 tag. The data comes from the list array. So something like this:
HTML:
<div id="output">
<h2 id="funny-day">Funny day: (HERE IS WHERE I WANT THE OUTPUT TO BE)</h2>
</div>
Javascript:
//Get elements
var funny-day = document.getElementById("funny-day");
//Array
var list = ["Sunny", "Cloudy", "Rainy"]
//Function to output array
var index = 0;
markiser.innerHTML = markiser.textContent;
setInterval(function() {
var text = (list[index++ % list.length]).toString();
markiser.innerHTML += text; <<Not working ofcourse since it only appends
}, 2000);
Important note is that I want to keep the “Funny day: ” inside the h2 tag because of SEO purposes.
2
Answers
Why don’t you add a tag specificly for your data like
<span class="data">yourdata</span>
I edited a few things that made no sense, for example your function cannot have
-
in it, Also, yourmarkiser
was not defined in the scope.Something like this?