I’m a novice javascript programmer and I always have trouble with the setInterval. W3Schools makes it look so easy but I can never get it to work when i need to. Here I have a span I want to make ‘flash’.
var id = window.setInterval(function(){
if($("#span1").css("color") == "red"){
$("#span1").css("color","blue");
}
else{
$("#span1").css("color","red");}
}, 100);
I keep getting a SYNTAX ERROR: Unexpected token ILLEGAL. What am I doing wrong here?
NOTE: I know there’s some jQuery method that could handle this easily. I’m trying to gain a better understanding of this JS function.
UPDATE I fixed the syntax error. (Missing quotation). Now I get an error undefined.
You probably copy and pasted the code and it has some bad characters in it. Try re-typing the code manually in a new file.
Side-note, you can make the whole thing a hell of a lot more efficient and reliable: