ho un menu con una serie di link...
quando faccio click su un link devo attribuirli una classe CSS che imposta un background-color evidenziandolo
ad ogni click devo reimpostare il valore di default per i link che non sono stati cliccati, vi posto un po di codice......
è corretto o esiste una via più semplice?codice:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title></title> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <script type="text/javascript"> function whatever(e){ var e=e? e : window.event; var event_element=e.target? e.target : e.srcElement; //alert(event_element.tagName); return event_element; } function init(){ var ob = document.getElementById('menu'); var l = ob.getElementsByTagName('a'); for(var i=0; i<l.length; i++){ l[i].onclick = function(e){ var t = whatever(e); alert(t) if(this==t){ alert('sono uguali !') // imposto il background }// altrimenti imposto background di default } } } window.onload = init; </script> <style type="text/css"> </style> </head> <body> <ul id="menu"> [*]link 1 [*]link 2 [*]link 3 [/list] </body> </html>
grazie![]()