Tengo el siguiente código:
Código HTML:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <style type="text/css"> ul {margin:0;padding:0;} li {list-style:none;} ul.menu li:hover, ul.menu li.over {background:#FF0000;} </style> </head> <body> <script type="text/javascript"> startList = function() { if (document.all&&document.getElementsByTagName) { navRoot = document.getElementsByTagName('ul').className="menu"; for (i=0; i<navRoot.childNodes.length; i++) { node = navRoot.childNodes[i]; if (node.nodeName=="LI") { node.onmouseover=function() { this.className+=" over"; } node.onmouseout=function() { this.className=this.className.replace(" over", ""); } } } } } window.onload=startList; </script> <ul class="menu"> <li>aaaaaa</li> <li>bbbbbb</li> </ul> </body> </html>
El problema está en esta línea:
navRoot = document.getElementsByTagName('ul').className="men u";
Ya que si en vez de getElementsByTagName uso el getElementById y le pongo <ul id="menu"> sí funciona.
Pero yo no quiero usar ID, sino clases... como hago ??
Es sencillo lo que pregunto ??