See http://docs.jquery.com/UI/Accordion#method-activate " Signature: .accordion( 'activate' , index ) Activate a content part of the Accordion programmatically. The index can be a zero-indexed number to match the position of the header to close or a Selector matching an element. "
This method currently does not accept a selector, only a numeric index. Since you want the 2nd section open, and it's zero-based: $('#accordion').accordion('activate', 1 ); Alternatively, you could initialize the accordion with this section active: $("#accordion").accordion({ active: 1, collapsible: true }); It seems this option accepts more types than the method, including selectors. See http://docs.jquery.com/UI/Accordion#option-active - Richard On Wed, Dec 16, 2009 at 4:22 PM, TC <tc_online2...@yahoo.com> wrote: > I'm trying to get the Accordion to open to a particular item when > loaded. I think the activate method should do this but I can't get it > to work. I created a test page and the item I'm trying to get it to > open to is in the 2nd section, the 2nd item from the bottom. The page > is at http://www.ofthejungle.com/testaccordion.php -- can anyone see > what I'm doing wrong? > > Not sure if I can paste the page source but here goes: > <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:// > www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> > <html xmlns="http://www.w3.org/1999/xhtml"> > <head> > > <link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/ > jqueryui/1.7.2/themes/ui-lightness/jquery-ui.css<http://ajax.googleapis.com/ajax/libs/%0Ajqueryui/1.7.2/themes/ui-lightness/jquery-ui.css>" > type="text/css" > media="all" /> > <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/ > jquery.min.js" type="text/javascript"></script> > <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/ > jquery-ui.min.js<http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/%0Ajquery-ui.min.js>" > type="text/javascript"></script> > > <script type="text/javascript"> > $(function() { > $("#accordion").accordion({ > collapsible: true > }); > }); > > $(document).ready(function() { > $('#accordion').accordion('activate','#anchor2_17'); > //$("#accordion").accordion('activate', 11 ); > //$('#accordion').accordion('activate', '#accordion > > div:has > (#anchor2_17) > h3'); > }); > > </script> > > </head><body> > > <div class="demo" style="height:500px; width:500px"> > <div id="accordion"> > > <h3><a href="#">Section 1</a></h3> > <div style="height:100px"> > <a id="anchor1_1" href="1_1.html">num1</a> <br/> > <a id="anchor1_2" href="1_2.html">num1</a> <br/> > <a id="anchor1_3" href="1_3.html">num1</a> <br/> > </div> > > <h3><a href="#">Section 2</a></h3> > <div style="height:100px"> > <a id="anchor2_1" href="2_1.html">num1</a> <br/> > <a id="anchor2_2" href="2_2.html">num1</a> <br/> > <a id="anchor2_3" href="2_3.html">num1</a> <br/> > <a id="anchor2_4" href="2_3.html">num1</a> <br/> > <a id="anchor2_5" href="2_3.html">num1</a> <br/> > <a id="anchor2_6" href="2_3.html">num1</a> <br/> > <a id="anchor2_7" href="2_3.html">num1</a> <br/> > <a id="anchor2_8" href="2_3.html">num1</a> <br/> > <a id="anchor2_9" href="2_3.html">num1</a> <br/> > <a id="anchor2_10" href="2_3.html">num1</a> <br/> > <a id="anchor2_11" href="2_3.html">num1</a> <br/> > <a id="anchor2_12" href="2_3.html">num1</a> <br/> > <a id="anchor2_13" href="2_3.html">num1</a> <br/> > <a id="anchor2_14" href="2_3.html">num1</a> <br/> > <a id="anchor2_15" href="2_3.html">num1</a> <br/> > <a id="anchor2_16" href="2_3.html">num1</a> <br/> > <a id="anchor2_17" href="2_3.html">num1</a> <br/> > <a id="anchor2_18" href="2_3.html">num1</a> <br/> > </div> > > <h3><a href="#">Section 3</a></h3> > <div style="height:100px"> > <a id="anchor3_1" href="3_1.html">num1</a> <br/> > <a id="anchor3_2" href="3_2.html">num1</a> <br/> > <a id="anchor3_3" href="3_3.html">num1</a> <br/> > </div> > > > </div> > </div> > > </body></html> > > -- > > You received this message because you are subscribed to the Google Groups > "jQuery UI" group. > To post to this group, send email to jquery...@googlegroups.com. > To unsubscribe from this group, send email to > jquery-ui+unsubscr...@googlegroups.com<jquery-ui%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/jquery-ui?hl=en. > > > -- You received this message because you are subscribed to the Google Groups "jQuery UI" group. To post to this group, send email to jquery...@googlegroups.com. To unsubscribe from this group, send email to jquery-ui+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/jquery-ui?hl=en.