ciprian ciprian - 1 year ago 153
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";

Answer Source

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];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download