New to JS. One thing I can't seem to wrap my head around is writing the proper code for changing an event back and forth.
For example, changing a color, back and forth on clicks, from red to black.
var titles = document.getElementById("titles");
function changeColor()
{
if(titles.style.color="black")
titles.style.color="red";
else
titles.style.color="black";
};
titles.addEventListener("click", changeColor);
I know this concept is a simple one, but when it comes to more complex things like having onclicks that open menus with other more complex things, without understanding this I'm going to have issues.
my problem is I don't understand how to control the second half of the code. I can change a color to red, but how do I change it back.