JavaScript event prevent default

JavaScript event preventdefault is a method for intervening event actions preventing normal events behavior

Take for instance you have an anchor on a page when a user clicks on it the browser by default navigates to a url in it's href attribute

preventdefault syntax

/// HTML
<a href="/" id="home">
    home
</a>

/// JavaScript
home.addEventListener('click', function(event){
    event.preventdefault()
    // rest of
    // the code
})

Comments

Popular posts from this blog

FlappingBird Postmortem (JS13K)

JavaScript introduction to variables

FlappingBird JS13K Games

How to target all elements of a given class name in JavaScript

Zedplug will be decommissioned on November 30th