I have the following code
<HTML>
<HEAD>
<style type="text/css">
.setbgcolor{
background-color:blue;
}
</style>
<script type="text/javascript">
function setbg(id){
document.getElementById(id).className = "setbgcolor";
}
</script>
</HEAD>
<BODY>
<div onclick="setbg(this.id)" id="bgcolor">Label1</div>
<div>Label2</div>
</BODY>
</HTML>
Now, the problem is that- when i click on Label2, background color should be removed from the first div and should get applied to the second div. Can someone help me out?
Probably you need something like a variable that stores the previously clicked div.
For example:
Of course you can use a shorter variable name!