Jquery get hash value

Let’s say you have a link like this

<a href="http://ibnuyahya.com/list#123">my link </a>

and you want to get value after hash, you can use this.hash to get hash value in a link for example

$('a').click(function(){
    alert( this.hash ); //return #123
});

if you don’t want to include hash # in your result, just add slice(1)

$('a').click(function(){
    alert( this.hash.slice(1) ); //return 123
});


About ibnuyahya

Ibnuyahya has written 104 post in this blog.

Ibnuyahya merupakan seorang software developer dan freelance consultant. Berpengalaman lebih dari 10 tahun dalam membangunkan perisian dari embedded sistem menggunakan micro-controller, windows application, mobile, image processing, artificial intelligent dan akhirnya menumpukan sepenuh tenaga dalam web application.