jQuery anchor detection

Here’s a snippet to catch the anchor # in url’s with jQuery and do something with it. I needed this for ultra simple jQuery tabs.

$(document).ready(function() {
	// for page reload
	if(window.location.hash.length > 1) {
		// hash is found, similate click
		$('.tabs a[rel=' +window.location.hash.substring(1)+ ']').click();
	}
});
 
// dynamic change
$(window).bind('hashchange', function() {
	// hash is found, similate click
	$('.tabs a[rel=' +window.location.hash.substring(1)+ ']').click();
});