Reputation: 960
I'm trying to define default active item in my accordion menu:
function activate_accordion(course_id){
var active_item = '';
if (course_id == false){
active_item = false;
}
else {
active_item = $('.accordion div[id="course-' + course_id + '"]').attr('active');
}
alert(active_item);
var icons = {
header: "../../img/plus.png",
activeHeader: "../../img/minus.png"
};
$( ".accordion" ).accordion({
collapsible: true,
icons: icons,
active: active_item,
heightStyle: "content"
});
}
My JsFiddle: http://jsfiddle.net/fvMre/ Accordion works but I encouter two problems:
Any ideas?
Upvotes: 0
Views: 149
Reputation: 41
We can load the images through "CSS" class name.
var icons = {
header: "plus",
activeHeader: "minus"
};
CSS are:
<style>
.plus
{
background-image:url(../../img/plus.png);
}
.minus
{
background-image:url(../../img/minus.png);
}
</style>
Upvotes: 1
Reputation: 56519
jQuery accordion UI
already has its default + and - icons.
This can be activated using
icons: {
"header": "ui-icon-plus",
"activeHeader": "ui-icon-minus"
}
from docs, "active" can be a bool or int 0 and 1. since your code returns numeric, you can follow what reyaner said.
active: parseInt(active_item)
Finally your accordion
code should be like
$(".accordion").accordion({
collapsible: true,
active: parseInt(active_item),
heightStyle: "content",
icons: {
"header": "ui-icon-plus",
"activeHeader": "ui-icon-minus"
}
});
Check this JSFiddle
Upvotes: 1
Reputation: 2819
i cant help you with the icons, but for the active element, parse it to Int
active_item = parseInt(active_item)
ah and for the icons, dont you have to set a class, not a path?
Upvotes: 1