Javascript correct but doesn't work

Why does my code show up with no errors in the error console yet it doesn’t work! It looks all good and shows up as good yet it does not work!

Could you post the code? Without it we can only guess what could be going wrong …

var flashelm = document.getElementById(‘blinkClass’);
var flashinter = 1000 //in milliseconds 1000/sec
var flashcolor = “blue”

function flashit(){

if (flashelm.style.color == '')
	flashelm..style.color = flashcolor
	else
	flashelm.style.color = ""
	
	setInterval ("flashelm()", flashinter)
}
  1. There is a typo in this line

flashelm.[COLOR="Red"].[/COLOR]style.color

(two dots)

  1. Do you call the function flashit()? Why do you use a function, btw, you can just put the complete code like so

var flashelm = document.getElementById('blinkClass');
var flashinter = 1000 //in milliseconds 1000/sec
var flashcolor = "blue"

if (flashelm.style.color == '')
flashelm.style.color = flashcolor {
} else {
flashelm.style.color = ""
}
setInterval ("flashelm()", flashinter)

just before </body> (in <script> tags of course)

Typos are going to do me in…
Thank you for the help!

flashelm.style.color = flashcolor {

I am getting a missing; before statement error now?

Oops, put the curly bracket on the wrong line. Should be:


var flashelm = document.getElementById('blinkClass');
var flashinter = 1000; //in milliseconds 1000/sec
var flashcolor = "blue";

if (flashelm.style.color == '') {
flashelm.style.color = flashcolor;
} else {
flashelm.style.color = "";
}
setInterval ("flashelm()", flashinter);

Sorry! :slight_smile:

I did try changing it but when I did that I get a message saying

flashelm is null

??

var flashelm = document.getElementById('blinkClass');
var flashinter = 1000 //in milliseconds 1000/sec
var flashcolor = "blue"

if (flashelm.style.color == '')
flashelm.style.color = flashcolor {
} else {
flashelm.style.color = ""
}
setInterval ("flashelm()", flashinter)

If flashelm is a global function it can’t be a global variable at the same time…

any advice of fixing it? tried a couple things but they don’t work
still a baby with Javascript!!!

Your original code looks like the function has a different name. Possibly it is just the call to the function that is wrong. Perhaps the following does what you are after:

var flashelm = document.getElementById('blinkClass');
var flashinter = 1000 //in milliseconds 1000/sec
var flashcolor = "blue"

function flashit(){

if (flashelm.style.color == '')
flashelm..style.color = flashcolor
else
flashelm.style.color = ""

setInterval ([B]flashit[/B], flashinter)
}

If flashelm is null, then you don’t have an element with ID “blinkClass” in your document, as document.getElementById() returns null on a non-existent ID.