Skip to content
Advertisement

innerHTML disappearing quickly after displaying

I was trying to make a “find and replace” page and my code is working properly except that the resulting string is only displayed for a split second before it disappears and the form is reset

Here is the HTML

JavaScript

Here is the js

JavaScript

Advertisement

Answer

You will have to prevent the form from submitting, either by:
– Using findReplace as the submit eventHandler and calling event.preventDefault()
– Adding type="button" to the button element. (h/t radulfr)
– Adding onsubmit="return false" to your form element:

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement