Thanks guys, I've tried messing around with both examples but it's too advanced for me at the moment so I'll have to go back to the basic javascript tutorials before I understand what I'm doing. Man being a noob sucks!
There's a crap ton of tutorials and things on the internet but I find a lot of the stuff people post includes a lot of needlessly complicated stuff. W3schools is good in that respect, they keep it simple.
[edit: update]
I managed to get the previous box to close when a new one is clicked.
I knew it was simple, I just didn't know how to declare a global:
var last=null;
function toggle(a)
{
// Make the selected command title stand out.
if(a.style.color=="yellow") a.style.color="#66CCCC"; else a.style.color="yellow";
// Toggle visibility of content.
e=a.nextSibling;
e=e.nextSibling;
e=e.nextSibling; //Yes this is messy!
if(e.style.display=="block"){
e.style.display="none";
}
else{
e.style.display="block";
if(last&&last!=a&&last.style.color=="yellow") toggle(last);
}
last = a;
return;
}
All the examples I found where running for-loops and checking every element instead of just storing the last one that was clicked!
The
e=e.nextSibling part is really bad but I can't figure out how to grab the
command_content div that is within the clicked
command div. (The parameter 'a' is the id of the command clicked.)
Shh... you're pretty.