I have following a tags:
Any tab1 Label
tab2 Label
Any tab3 Label<
function tellMyName() {
var str = this.href.split("#")[1];
alert(str);
}
Not all the time only the hash part will be displayed on the link. Sometimes the Host is added to the href
. By splitting the href with the hash
(#) and get the second part of the split string, you'll get what you want.
function tellMyName() {
alert(this.hash.replace('#',''));
}
$('a').click(tellMyName);
function tellMyName() {
var str = this.prop("hash").substr(1)
alert(str);
}
this.prop("hash") will return the hash value i.e #tab1
You can use something like this:
...
var activeTab = $(this).attr("href");
$(activeTab).fadeIn();
...
This use href="#tab-id" for locate #tab-id element you want, and fade in.
<script>
function tellMyName()
{
var text = this.href;
text = text.replace("#","");
alert(text);
}
</script>
You can do something like this
var fragment = $('a#my-link')[0].hash.substr(1);
Check it out.