How to destroy / Delete Active accordion using jquery

China☆狼群 提交于 2019-12-12 16:23:01

问题


How can we destroy active accordion with all the content is have in it.

I started with this function

function DesctroyThisAccordion() {
var active = jQuery("#accordion").accordion('option', 'active');
 jQuery("#accordion").accordion('option', 'active').remove('h3');
jQuery("#accordion").accordion('option', 'active').remove('div');
}

I am using jQuery UI plugin for accordion

I am trying to find the active accordion and delete its h3 and div content.

i works if i select the last in accordion

//jQuery("h3[class^='Title']:last").remove('h3');
//jQuery("div[class^='ui-accordion-content']:last").remove('div');

But i want it for active accordion

any help would be greatly appreciated.


回答1:


I used:

$("#myAccordion").accordion("destroy");    // Removes the accordion bits
$("#myAccordion").empty();                // Clears the contents

If you only empty the accordion container, it still retains accordion properties and will not be reusable as an accordion. Here's the destroy documentation.




回答2:


Since i didn't find any help on this question. I found solution, which may be helpful for any who are in same need.

jQuery("h3[class^='Title'][aria-selected='true']").remove('h3');
jQuery("div[class^='ui-accordion-content'][style^='display: block;']").remove('div');



回答3:


How about

$("#accordion h3").remove();
$("#accordion-cost div").remove();

Removes all h3 and div elements inside accordion.



来源:https://stackoverflow.com/questions/8314729/how-to-destroy-delete-active-accordion-using-jquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!