Hi all,
This is my second day at JS. Need some basic help. I have an html table with all cell having a blue background. When you click on a cell it changes to yellow. I'm successful at this basic example.
What I would like next, is the second cell I click on have it turn yellow (which it does) but have the previous cell turn back to blue. I imagine this can be accomplished with Global variables but I'm having trouble getting it to work.
Here's what I have:
When I call this function I do:
Can someone help me figure out how to keep track of the previous element?
Thank you in advance!
This is my second day at JS. Need some basic help. I have an html table with all cell having a blue background. When you click on a cell it changes to yellow. I'm successful at this basic example.
What I would like next, is the second cell I click on have it turn yellow (which it does) but have the previous cell turn back to blue. I imagine this can be accomplished with Global variables but I'm having trouble getting it to work.
Here's what I have:
Code:
function setStyle(x)
{
document.getElementById(x).style.background="yellow";
//alert(x);
}
When I call this function I do:
Code:
onclick="setStyle(this.id)"
Can someone help me figure out how to keep track of the previous element?
Thank you in advance!