html - Javascript Dont Change The Background -


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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -