I am using this script to scroll to an anchor:
$( document ).ready(function(e)
{
var $root = $('html, body');
$('a').click(function(e) {
e.preventDefault();
var href = $.attr(this, 'href');
if(href!=='javascript:void(0)' && href!=='javascript:void(0);'){
$root.animate({
scrollTop: $(href).offset().top-100
}, 1000, function (e) {
e.preventDefault();
window.location.hash = href;
});
return false;
}
});
});
However, after I clicked a link (and the animation finishes), I get the following error twice: Uncaught TypeError: Cannot read property 'preventDefault' of undefined
I don't understand why. I tried to add the e
to the function but it still gives the error. Could someone give some background information?