Squarepusher Posted December 19, 2015 Share Posted December 19, 2015 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 More sharing options...
Ingolme Posted December 19, 2015 Share Posted December 19, 2015 I think its because you put a capital "C" on "Change" Link to comment Share on other sites More sharing options...
Squarepusher Posted December 19, 2015 Author Share Posted December 19, 2015 (edited) I thought the opposite way and changed "c" to "C" because it also didn't work. Never mind, I found the error. Instead of "document.addEventListener" you must use window.addEventListener instead... Edited December 20, 2015 by Squarepusher Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now