Reputation: 21909
I'm using hashchange jQuery plugin from http://benalman.com/projects/jquery-hashchange-plugin/ to hook up an event when the window's location.hash changes.
I'd like to trigger a function when the hash changes that passes the new hash value (obtained with event.fragment
) and the current hash value (the value just before the event is fired).
Here's a snipped of what I'd like to achieve:
$(window).bind('hashchange', function(event){
myFunction(event.fragment, /* currentHash */);
});
Is this possible?
Upvotes: 0
Views: 1281
Reputation: 630429
There's a property on location:
$(window).bind('hashchange', function(event){
myFunction(event.fragment, location.hash);
});
Or, store it yourself:
var lastHash = location.hash; //set it initially
$(window).bind('hashchange', function(event){
myFunction(event.fragment, hashLash); //previous hash
lastHash = location.hash; //update it
});
Upvotes: 2