DEV Community

Cover image for When use preventDefault() in a dom?
Faisal Ahmed
Faisal Ahmed

Posted on

When use preventDefault() in a dom?

First case: When you create a form, inside the form, you create a button, and when the button has clicked.
Second case: Your inside the form or inside the div, button type or input type is submit.

-in this two cases, you use e.preventDefault();

otherwise, you can't see the output. Your output is ready but not show. It display too fast that you can't see it.

  • without using e.preventDefault();


  • with using e.preventDefault();

Top comments (0)

SurveyJS custom survey software

JavaScript Form Builder UI Component

Generate dynamic JSON-driven forms directly in your JavaScript app (Angular, React, Vue.js, jQuery) with a fully customizable drag-and-drop form builder. Easily integrate with any backend system and retain full ownership over your data, with no user or form submission limits.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay