It doesn't make sense to put a click event handler into a hashchange event.
Have look at my forked fiddle:
You can check the hash handling over the following url:
http://fiddle.jshell.net/y9X2D/35/show/
I just excluded the your click event code into a seperate function.
The click event now changes the url hash which fires the hashchange
event.
the hashchange
event then calls showDetail
.
Of course you can also call showDetail
directly without changing the hash.
$(window).hashchange( function(){
var hash = location.hash;
if(hash)
{
var element = $('.content-block-footer[hook="'+hash.substring(1)+'"]');
if(!element) element = $('.content-block-footer').first();
showDetail(element);
} else {
element = $('.content-block-footer').first();
showDetail(element);
}
});
$(document).ready(function() {
$(window).hashchange();
$(".content-block-footer").click(function () {
document.location.hash = $(this).attr('hook');
});
});