Animations

API

Arrays

Async

Basics

Challenges

Classes

Console

Dates

Debugging

DOM Elements

DOM Methods

DOM Navigation

DOM Properties

Event Listeners

Flow Control

Forms

Functions

Global Functions

JSON

Keywords

Libraries (3rd party)

Math

Modules

Objects

Snippets

String

Types

Widgets

Window Object

JavaScript - prevent default

The preventDefault() method cancels the event if it is cancelable, meaning that the default action that belongs to the event will not occur. For example, this can be useful when clicking on a submit button and preventing the form from submitting. Notice that this page does not refresh.

event.preventDefault();

http://www.w3schools.com/jsref/event_preventdefault.asp


document.body.onload = function ()
{
    document.getElementById("btnSubmit").addEventListener("click", function (event)
    {
        event.preventDefault()
        alert("You shall not pass!");
    });

    document.getElementById("checkbox1").addEventListener("click", function (event)
    {
        event.preventDefault()
        alert("You shall not be checked!");
    });
};