I am trying to create an if ... else if ... else statement in Javascript that will change the style of a specific CSS identifier based on a specific number. The if ... else code if ... else is not a problem, it is just like Javascript beginner (putting it a little ...) I'm not sure where to add CSS code to execute it. From what I understand, I would put it in the areas that I called "CSS CODE" below (sorry for the poorly formed code).
if (Number == 9) {CSS CODE} else if (Number == 8) {CSS CODE}
I looked at another question here, and the code that was provided to achieve this is below.
var element = document.getElementById("ElementID");
element.style.backgroundColor = "#fff";
When I put var at the top and element.style.etc in the CSS CODE section, it did not work properly.
As a side note, I need the whole style to be contained in the script, so adding a new class to it will not work. For the same thought, I cannot use jQuery for any of this or I would already :)
source
share