I'm working on a project that makes heavy use of jQuery tabs and Ajax. Loading data into the tabs is simplicity itself, but the data in the tabs needs to be filtered by a select box that sits outside the tabs div.
Here's where my problem starts. Let's say my tab makes an Ajax call to the URL "tab1.html." jQuery tabs changes this target into a hash value something like "#ui-tabs-10," but I can get the original URL through the following code:
$("#tabs").tabs({
select: function(event,ui) {
var url = $.data(ui.tab, 'load.tabs');
...do stuff with url
}
});
But I cannot seem to access the ui.tab object outside this event call. So my select box change event ends up looking like this:
var urls = {
0 : "tab1.html",
1 : "tab2.html",
2 : "tab3.html"
}
$('#selectBox').change(function(){
var tabs = $("#tabs").tabs();
var id = $('#selectBox').attr("selectedIndex");
var selectedTab = tabs("option", "selected");
var newUrl = urls[selectedTab] + "?id=" + id;
tabs("url", selectedTab, newUrl);
tabs("load", selectedTab);
});
My problem is that hash map. I don't need it, and it duplicates info that I've already coded into the tabs div itself.
<div id="tabs">
<ul>
<li><a href="tab1.html">tab1</a></li>
<li><a href="tab2.html">tab2</a></li>
<li><a href="tab3.html">tab3</a></li>
</ul>
</div>
I've exhausted both the docs and the DOM tree in Firebug to no avail. Any ideas on how I can retrieve the href from outside a tab event?
I'm using jQuery UI version 1.7.2. Muchos gracias in advance. You guys are the best.
The following will write out the href's to the console.
Demo that alerts the ajax tab href's here
$('#tabs a').each(function() {
var href = $.data(this, 'href.tabs');
console.log(href);
})
var links = $("#thetabs > ul").find("li a");
var url = $.data(links[tabnum], 'href.tabs');
tabnum is the zero based index of the tab you want the url from
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With