Jump to content

bgChange onclick


kurt.santo

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...