I’m working on a site that uses JQuery UI to display some tabs and accordions, but I’m running into a road block when I use a variable inside an elements initialization. Basically, I need to read some numbers out of a URL stuff/1/0 and selectively activate parts of an accordion based on them. This is what I have so far:
$(document).ready(function() {
//Get URL
var href = window.location.pathname;
//Get Segments
var segs = href.split('/');
if(segs.length > 2)
{
var active_tab = segs[segs.length - 1];
var active_unit = segs[segs.length - 2];
alert(active_tab);
alert(active_unit);
//Check if its a number
if(!isNaN(active_unit))
{
//Accordions
$( ".accordion" ).accordion
({
active: active_unit,
autoHeight: false,
collapsible: true
});
}
//Check if its a number
if(!isNaN(active_tab))
{
//Tabs
$( ".tabs" ).tabs
({
selected: active_tab
});
}
}
});
But, this doesn’t seem to affect the accordion at all, even though I am successfully getting the URL segments. Obviously, this is because the active_tab/active_unit variables are not being parsed into the accordion/tab set up. Is there some other way to accomplish this? Thanks beforehand!
The values you parsed out of the url are strings. You need to parse them into numbers:
It probably wasn’t working because the accordian plugin was expecting a number.