I am developing a Struts2 application and have been using <sj:accordion> (https://code.google.com/p/struts2-jquery/wiki/AccordionTag).
Until now, I have been initializing it on my jsp page by hardcoding the value I want in the tags but is there anyway to initialize it using JavaScript?
Here is what I'm trying to solve. I have an accordion that I initialize using (all values are hard-coded):
<sj:accordion
id="accordionremote"
active="0"
/>
The 'active' element allows me to decide which <sj:accordionItem> is active/open on page load. Is there any other way to initialize the active element or which <sj:accordionItem> is open on page-load without hard-coding it?
I have tried using $("#accordion").accordion('activate', 0); as described by jquery accordion: activate option using Struts <sj:accordion> but it does not work when I place it inside a <script> element.
Figured it out! You have to use $("#accordion").accordion({active : 1});
<sj:accordion id="accordion"
heightStyle="content"
animate="true"
collapsible="true"
active="0"
onCreateTopics="initAccd"
>
<sj:accordionItem title="item1"></sj:accordionItem>
<sj:accordionItem title="item2"></sj:accordionItem>
</sj:accordion>
<script>
//going to initialize the accordion
$.subscribe("initAccd", function (event, data){
//activate the 2nd item i.e. item2
$("#accordion").accordion({active : 1});
});
</script>