Clicca ripetutamente sui 2 cerchi e cambia il loro colore.
JavaScript può accedere agli elementi tramite evt.target.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?xml version="1.0"?> <svg xmlns="http://www.w3.org/2000/svg" width="640" height="480"> <script type="text/ecmascript"> <![CDATA[ function cambiaColore(evt) { var elemento=evt.target; var colore=elemento.getAttribute("fill"); if(colore == "blue") elemento.setAttribute("fill", "red"); else elemento.setAttribute("fill", "blue"); } ]]> </script> <circle cx="150" cy="150" r="100" fill="blue" onclick="cambiaColore(evt)"/> <circle cx="400" cy="150" r="100" fill="red" onclick="cambiaColore(evt)"/> </svg> |