Jump to content

bgChange onclick


kurt.santo
 Share

Recommended Posts

Have this great code for a bgChange onmouseover. Is there a way to change it to change color when clicked upon and change back to standard color when another item is clicked? The script is:

window.onload=function(){var li=document.getElementsByTagName("li");for(var i=0;i<li.length;i++){	li[i].onmouseover=function(){		this.style.backgroundColor='#cacb7f';		};		li[i].onmouseout=function(){		this.style.backgroundColor='#d9d9a2';		};	}};

Kurt

Link to comment
Share on other sites

Have this great code for a bgChange onmouseover. Is there a way to change it to change color when clicked upon and change back to standard color when another item is clicked? The script is:
window.onload=function(){var li=document.getElementsByTagName("li");for(var i=0;i<li.length;i++){	li[i].onmouseover=function(){		this.style.backgroundColor='#cacb7f';		};		li[i].onmouseout=function(){		this.style.backgroundColor='#d9d9a2';		};	}};

Kurt

How about:
window.onload=function(){	var li=document.getElementsByTagName("li");	for(var i=0;i<li.length;i++){		li[i].onclick=function(){			var li=document.getElementsByTagName("li");			for(var i=0;i<li.length;i++){			li[i].style.backgroundColor='#d9d9a2';			};			this.style.backgroundColor='#cacb7f';		};	}};

Link to comment
Share on other sites

How about:
window.onload=function(){	var li=document.getElementsByTagName("li");	for(var i=0;i<li.length;i++){		li[i].onclick=function(){			var li=document.getElementsByTagName("li");			for(var i=0;i<li.length;i++){			li[i].style.backgroundColor='#d9d9a2';			};			this.style.backgroundColor='#cacb7f';		};	}};

I tried it, but it does not change the change the bg color for the li clicked upon, it rather does it for the parent li element. Also, when you click onto different li item it does not change the bg colour any more... Kurt
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...