Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get anchor value with jQuery

How do I get get the value after # in the link when that link is clicked?

$(".myLink").click(function(){ 
    ???
}

<a href="myPage.php?a=asdasdasd#value" class="myLink">link</a>
like image 982
santa Avatar asked Jan 27 '26 22:01

santa


2 Answers

$('a.myLink').click(function() {
  alert(this.hash);
  return false;
});
like image 148
js1568 Avatar answered Jan 29 '26 12:01

js1568


$(".myLink").click(function(evt){ 
    var arr = $(this).attr('href').split('#');
    alert(arr[1]);
    evt.preventDefault();
});
like image 30
ezmilhouse Avatar answered Jan 29 '26 12:01

ezmilhouse



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!