ciprian ciprian - 2 months ago 9x
jQuery Question

jQuery - Get url hash

I have three tabs on a page

  • Latest

  • Expired

  • Pending

When each tab is active, a hash is added to the url:

I am trying to add pagination fore each tab. So I was thinking of doing something like this:

But I don't know how to get the hash value by itself. Using

if( $(location).attr('hash') ) {
var tab = $(location).attr('hash');
var tab = "#latest";


getting hash

var hash = window.location.hash;

getting latest

var active = hash.match(/\#(\w+)/)[1];

getting page number

var num = hash.match(/p=(\d+)/)[1];