noor unnisa

noor unnisa

  • NA
  • 19
  • 2.2k

how to restore the list element style on clicking other elem

Nov 5 2015 5:08 AM
I am creating list elements dynamically and the  list element color should change when we click on it,.
 this  functionality am getting through the following code:
 
function addLeaf(sText) {
var element = null;
try {
element = document.createElement("li");
element.innerText = sText;
element.style.cursor = "pointer";
element.onclick = function (event) {
element.style.color = "red";
};
 
 
 
 
but when i clicked another list element ,the first clicked list element should become normal ie,.in black color,.
 
 
if  anyone can help 

Answers (1)