html - DOM with javascript not working -
i'm newbie web programming , can't understand why following code doesn't work.
it supposed remove permanently content of div element when button pressed, disappears while , reappears.
the code following:
<!doctype html> <html lang="es"> <head> </head> <body> <script type="text/javascript"> function prueba(){ document.getelementbyid('uno').innerhtml=""; } </script> <div id="uno">contenedor uno</div> <form onsubmit="prueba()"> <input type="submit" value="entrar" > </form> </body> </html>
i believe what's happening button submitting form, sends form web server reloads page. so:
- your "onsubmit" js runs , clears div content.
- your page reloads , content comes back.
try instead of form (i.e. remove surrounding form tag):
<button onclick="prueba()">entrar</button>
Comments
Post a Comment