kurt.santo Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
Reg Edit Posted October 31, 2007 Share Posted October 31, 2007 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 More sharing options...
kurt.santo Posted November 1, 2007 Author Share Posted November 1, 2007 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.