开发者

Get id of new and old content from jquery.ui.accordion

I want to launch an ajax call whenever an accordion tab is opened to get the content of that tab. For that I need to know what tab was left and what tab is opened. From the jquery documentation:

$('.ui-accordion').bind('accordionchange', function(event, ui) {
  ui.newHeader // jQuery object, activated header
  ui.oldHeader // jQuery object, previous header
  ui.newContent // jQuery object, act开发者_C百科ivated content
  ui.oldContent // jQuery object, previous content
});

In firebug I can see that what I need is the ui.newContent or ui.oldContent.

These appear to be the actually divs, so I somehow need to get at their id's.

function OnAccordionChanged(event, ui) {
    //get the id of the old tab
    var oldId = ui.oldContent.id;

    //apply (business) filters 
    //get the id of the new tab
    //fetch the content 
    //append to new tab
    //party
}

It's basically the verry first step where I fail :S


There seems to actually be a bug or something newContent will give you 'undefined' however newHeader will give you the

$(ui.newHeader).attr('id') will give the id of the h3 tag $(ui.newContent).attr('id') should give the id of the div, but does not. Instead it gives 'undefined' even just ui.newContent.attr('id') which should be ok stil gives undefined. Using the DOM tab in firebug i was able to determine a weird-improper work around

ui.newContent.prevObject.attr('id')

It seems that the div is actually in ui.newContent.prevObject which is a jQuery object... Seems to work flawlessly


You get the ID of a (jQuery) DOM object via

my_object.attr("id")
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜