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:

  1. your "onsubmit" js runs , clears div content.
  2. your page reloads , content comes back.

try instead of form (i.e. remove surrounding form tag):

<button onclick="prueba()">entrar</button> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -