Alex Rivera | Logout

how can i extract text after hash # in the href part from a tag?

Asked 2010-10-05T05:40:02.060
23

I have following a tags:

<a href="#tab1">Any tab1 Label</a>
<a href="#tab2">tab2 Label</a>
<a href="#tab3">Any tab3 Label</a>
<script>
function tellMyName()
{
    alert(this.href);
}

</script>

Now i want to bind the tellMyName function to all the a tags and get tab1 if Any tab1 Label is clicked, tab2 if tab2 Label is clicked and so on...

Edit
Report

1 Answer

6

You can do something like this

var fragment = $('a#my-link')[0].hash.substr(1);

Check it out.

answered 2010-10-05T05:55:19.953

Your Answer