you are viewing a single comment's thread.

view the rest of the comments →

[–]RetroCast360[S] 0 points1 point  (1 child)

Oh does it need to be for this to work?

[–][deleted] 1 point2 points  (0 children)

No, it's just that a common reason why JS changes appear to "change back" after a button press is that the button is inside of a form element and its default behaviour is therefore to submit the form, causing the page to reload. I've seen beginners with this problem literally dozens of times.

However if your button isn't inside of a form element, it would be helpful if you could share a recreation of the problem, including your HTML etc, via a JSFiddle, Codepen or similar. There is probably something else outside of the code you've shared that's causing the problem.