I need an expanding menu system but first I was practising on something even simpler to see the principle work.
HTML:
Code: Select all
<html>
<body>
<p id="para" onclick="toggle()">Paragraph</p>
</body>
</html>
Code: Select all
#para {
color:red;
}
Code: Select all
function toggle() {
if (document.getElementById("para").style.color=="red") {
document.getElementById("para").style.color="green" }
else {
document.getElementById("para").style.color="blue" }
}
Firstly I can only ever get one change to happen, "else" never kicks in. With "==" it goes to changes to blue, and with only a single "=" in the condition it goes green. Even if I write a load of jibberish in the condition it still changes colour, so it seems to ignore the "if" also.
I'm not sure about the whole document. bit either. Like I say, I've not started learning from the beginning because I don't have time, but I thought it'd be simple enough. Guess not.
Halp?