Let’s work together

Feel free to send me an email at chris@schalenborgh.be

Research Campus 18
3500 Hasselt
Belgium

jQuery anchor detection


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();
});