I\'m using JQuery UI to make tabs in my application. I needed the tabs to be linkable (direct link that opens the page and selects the correct tab). This is done by using a
As others have mentioned the code from @Mottie might have once worked on older versions of jQuery UI, but this has definitely stopped working. The jQuery UI Tabs api has changed quite a bit since that was written so here is an updated version that works with at least jQuery 1.10.2
Demo here: http://jsfiddle.net/xsx5u5g2/
var $tabs = $("#tabs");
$tabs.tabs({
create: function(event, ui) {
// Adjust hashes to not affect URL when clicked.
var widget = $tabs.data("uiTabs");
widget.panels.each(function(i){
this.id = "uiTab_" + this.id; // Prepend a custom string to tab id.
widget.anchors[i].hash = "#" + this.id;
$(widget.tabs[i]).attr("aria-controls", this.id);
});
},
activate: function(event, ui) {
// Add the original "clean" tab id to the URL hash.
window.location.hash = ui.newPanel.attr("id").replace("uiTab_", "");
},
});