html - Javascript Dont Change The Background -
this question has answer here:
i want change list background wont work
my code :
change(num, element){ var text if (num == 1){ ... } else if (num == 2) { ... } else { ... } document.getelementbyid('text').innerhtml = text; document.getelementbyclass("left").style.backgroundcolor = "black"; //<------ element.style.backgroundcolor = "white"; //<------ }
and html :
<ul> <li><a class="left" href="#" onclick="change(1,this)>first</a></li> <li><a class="left" href="#" onclick="change(2,this)>second</a></li> <li><a class="left" href="#" onclick="change(3,this)>third</a></li> </ul>
when click on 1 of list element , text changes background color won't ...
how can fix ?
thanks,
there's no such function getelementbyclass
, there's getelementsbyclassname
, wich returns array. need choose 1 want change out of array or use ids
Comments
Post a Comment