Jump to content

Adding a "hashChange" event by "addEventListener"?


Squarepusher

Recommended Posts

I tried to add a "hashChange" event to the body element using the "onload" event, but nothing happens when the hash changes:

document.addEventListener("hashChange", function() {
  alert(location.hash);
});

But t works when I add

onhashchange="alert(location.hash)"

to the body element? Why?

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...