Thursday, 8 August 2013

How can I make variables so that I don't have to repeat myself in future functions

How can I make variables so that I don't have to repeat myself in future
functions

WARNING!! I AM A NOVICE THROUGH AND THROUGH
Alright, so I know there have been a lot questions about Global variables,
and I think that's what I'm looking for, but, not exactly. Lately I've
been needing to call upon the same lines of code several times.
document.getElementById("example").style or similar to little things like
that but I need to continuously repeat.
My question is how do I make it so that I make one variable, outside of
the function, to save time writing these lines?
What I've been seeing is to simply write it outside like this var inferno
= document.getElementById("inferno"); but this is far from working.
This is my code right now, it's simple because I was just using it as a
test, but can anyone help me?
var inferno = document.getElementById("inferno");
function infernoClick () {
inferno.style.backgroundColor="red";
}

No comments:

Post a Comment