Hello I'm trying to change a word after each 3 seconds.
The Script:
<script type="text/javascript">
var text = ["Fysioterapeut", "Kiropraktor", "Praktiserende læge"];
var counter = 0;
var elem = document.getElementById("changeText");
setInterval(change, 3000);
function change() {
elem.innerHTML = text[counter];
counter++;
if(counter >= text.length) { counter = 0; }
}
</script>
The PHP/HTMl
$title = "FIND DEN RIGTIGE <span id='changeText'>Fysioterapeut</span> i dag";
The console says elem is NULL ? Why is that?
The script is running clearly but the text is not changing. Anybody know why?
changeTextor after? It is possible that you are trying to access element before it is in the document.