Salve a tutti, ho appena intrapreso il js sia qui su html.it che su w3schools.
Ho provato a fare qualcosa di molto semplice ma mi dice:
"Uncaught TypeError: Undefined is not a function".
P.s. i<20 è totalmente casuale, volevo soltanto provare come funziona.
Ho provato anche a chiudere con else ma non funziona lo stesso.
Il codice è il seguente:
codice:
<!doctype html><html>
<head>
<meta charset="UTF-8">
<title>Una prova JS</title>
<style>
#text
{
width:200px;
position:absolute;
left:20px;
transition:all 1s ease;
}
</style>
</head>
<body>
<p id="text">Testo di prova
</p>
<script type="text/javascript">
var i;
for(i=0; i<20; i++)
{
if(document.GetElementById("text").style.left == "20px" )
{
document.GetElementById("text").style.left = "600px";
}
else if(document.GetElementById("text").style.left == "600px" )
{
document.GetElementById("text").style.left = "20px";
}
}
</script>
</body>
</html>