How to stop default link click behavior with jQuery How to stop default link click behavior with jQuery javascript javascript

How to stop default link click behavior with jQuery


e.preventDefault();

from https://developer.mozilla.org/en-US/docs/Web/API/event.preventDefault

Cancels the event if it is cancelable, without stopping further propagation of the event.


$('.update-cart').click(function(e) {    updateCartWidget();    e.stopPropagation();    e.preventDefault();});$('.update-cart').click(function() {    updateCartWidget();    return false;});

The following methods achieve the exact same thing.


You want e.preventDefault() to prevent the default functionality from occurring.

Or have return false from your method.

preventDefault prevents the default functionality and stopPropagation prevents the event from bubbling up to container elements.