Using JavaScript to Temporarily Prevent Clicks and Form Submissions

When you test interactivity of a web page by clicking a link or submitting a form, you sometimes don’t want to be redirected to a new page. Using JavaScript in your browser’s console, you can easily make this happen.

  1. Open your browser’s inspector and inspect the element (link or button) that when clicked on, won’t take you to a new page
  2. In your browser’s console, add the following JS
$0.addEventListener("click", function(e) {
     e.preventDefault();
});