Nov 10, 2018

How to prevent web browser’s default response to an event

If you want to prevent the web browser’s normal response to an event, use preventDefault(). By default, when you click on the hyperlink, the normal response of the event is to transfer you to the url represented in the hyperlinks href attribute.

    <a href="http://i88.ca" id="i88">i88.ca</a>

Here clicking on the hyperlink transfers you to i88.ca. If you want to prevent this default behavior, use preventDefault():


$("a").click(function (e) {
    e.preventDefault();
    // do something else
});