Jump to content

getElementByClass


tijger0407

Recommended Posts

Currently having this code <script language="javascript" type="text/javascript"> function changecolor(){ document.getElementByClass('menu').style.backgroundColor='#FFFFFF'; } function revertcolor(){ document.getElementByClass('menu').style.backgroundColor='#565656'; } </script>and <a href="home.php" alt="Me"> <div class="menu" onmouseover="changecolor()" onmouseout="revertcolor()"> <p>Me</p> </div> </a>Now I want to change the background of the div with the mouse over used by the functionATM it aint working and not having a clue why it aint workingAny help would be apriciated

Link to comment
Share on other sites

I'm pretty sure there's no such thing as getElementByClass.maybe this might help instead? http://www.w3schools.com/jsref/met_doc_getelementsbyname.aspor give it an ID an use getElementById instead, which I believe is the preferred way of doing it.

Link to comment
Share on other sites

The method is getElementsByClassName(), and it is not consistently implemented. You can build a collection using getElementsByTagName() and then loop through it to filter the className property. That's a pretty common technique.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...