javascript - JS works fine in Chrome but not in FireFox -


it's simple window scroll triggers when user clicks on nav item life of me cant seem figure out why ff wont recognise it, i've read similar q&a's recommend defining var's first i've done, appreciated.

heres code:

$("#mynavbar a").on('click', function(){ var hash = this.hash;  //make sure this.hash has value if (hash !== ""){     //prevent default anchor click behavior     event.preventdefault();       //use jquerys animate() method add smooth scroll     $('html, body').animate({         scrolltop: $(hash).offset().top     }, 800, function(){          window.location.hash = hash;     }); } // end of if }); 

this "works" in chrome because chrome implements non-standard window.event property.

as noted in comments, should use event argument provided jquery event handler instead.

$("#mynavbar a").on('click', function(event){     ...     event.preventdefault();     ... }); 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -