Skip to content Skip to sidebar Skip to footer

Html Javascript Reverts To Default After Javascript Has Run

I am learning javascript and we have been given the task of changing image / colour of paragraph from the click of the button. My code works but I had to add an alert() to stop it

Solution 1:

You are submitting a form. That causes the page to be reloaded and reset.

Use type="button" (and you might as well remove the form entirely while you are at it) or call preventDefault on the event object (the first argument to changeImage).

Post a Comment for "Html Javascript Reverts To Default After Javascript Has Run"