javascript - Get reference to a JQuery UI Accordion Header -


i have jquery accordion below;

<div id="accordion">  <h3 class="ui-accordion-header"><a id="link1" href="#">first header</a></h3>   <div id="div1">first content</div>  <h3 class="ui-accordion-header"><a id="link2" href="#">second header</a></h3>   <div id="div2">second content</div> </div> 

the accordion generated this:

$("#accordion").accordion({   collapsible:true,   active:false,   navigation:true,   autoheight:false,   change:function(event, ui){     var index = $(this).find("h3").index(ui.newheader[0]);     var header = $(this).find("h3")[index].find("a"); //<--- problem line     var currentheaderid = (header.attr("id")); //<--id need   } }); 

jsfiddle link

the accordion loading fine. i'm trying achieve 2 things.

1- id of href element inside tag of header opened (i.e. ids link1 , link2). code above inside change event giving me index of header. i'm struggling next line (var header = ....) working. able

2- resolved when user clicks on opened header, section closed, sections become closed. i'm not sure how can achieve this. able help?

thanks

when accordion changes, jquery object wrapping active header's <h3> element passed in ui.newheader, have use find():

var currentheaderid = ui.newheader.find("a").attr("id"); 

updated fiddle here.


Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -