Reputation: 10552
Is it possible to use javascript/jquery to append something on the end of a url when a link is clicked?
For example, I have 5 tabs on a page (product.php), when I click a tab, then that tab opens. What I want to do is have the URL change to product.php#tab-3 (or whichever number tab is clicked) when you click on it.
The reason I am doing this is so that users will be able to bookmark the page on a specific tab.
Thanks
Upvotes: 1
Views: 3675
Reputation: 39
maybe implement something like this
<div class="tabs" name="tab1">your tab handler 1</div>
<div class="tabs" name="tab2">your tab handler 2</div>
<div class="tabs" name="tab3">your tab handler 3</div>
And your code
$(".tabs").click(function()
{
location.hash = $(this).attr("name");
});
Kind of easy way to automatic do what you want if you have keep changing tabs and order...
Upvotes: 1
Reputation: 138007
No need to use JavaScript:
<a href="#tab3">click</a>
You can still use JavaScript if you need it though:
location.hash = "tab3";
Upvotes: 3
Reputation: 71
You can use the plugin jQuery Address http://www.asual.com/jquery/address/
Upvotes: 1