In almost all of the sample scripts / templates I can find, I see event.preventDefault(); at the end of a function, for example:
$('.navbar-nav li a').bind('click', function(event) { var $anchor = $(this); $('html, body').stop().animate({ scrollTop: $($anchor.attr('href')).offset().top }, 1500, 'easeInOutExpo'); event.preventDefault(); });
From my point of view, the idea is that "immediately stop the default behavior and then do everything we have to do," for example:
$('.navbar-nav li a').bind('click', function(event) { event.preventDefault(); var $anchor = $(this); $('html, body').stop().animate({ scrollTop: $($anchor.attr('href')).offset().top }, 1500, 'easeInOutExpo'); });
So what am I missing?
jquery preventdefault
Olivier pons
source share