Ho appena iniziato con il js, stavo provando a scrivere una funzione che spostasse di 100px un div, non capisco perchč non va.
Lo stile correlato:codice:<html> <head> <title>Prova JavaScript</title> <link href="provajs.css" rel="stylesheet" type="text/css"> <script> function on(id){ var div=document.getElementById(id).style.top; var h=div.replace("px", ""); var h2=parseInt(h); h2+=100; document.getElementById(id).style.top=h2+"px"; } </script> </head> <body> <div id="container" > <div id="myHeader" onclick="on('myHeader')"> ciao </div> </div> </body> </html>
codice:#myHeader { width: 20%; height: 20%; margin: auto; background-color: rgb(255,0,0); position:relative; top:100px; border: solid; }

Rispondi quotando