0
I am using the code below to clone the accordion. But while trying to expand the accordion that has been cloned the captured event triggers the parent accordion. I know the clone event is limited but how to solve this problem?
<div class="container">
<div class="row">
<div class="col-md-12">
<button class="btn btn-primary btn-add-panel">
<span class="glyphicon glyphicon-plus"></span> Novo
</button>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="panel-group" id="accordion" role="tablist" aria-multiselectable="true">
<div class="panel panel-default">
<div class="panel-heading" role="tab" id="heading-1">
<h4 class="panel-title">
<a role="button" data-toggle="collapse" data-parent="#accordion" href="#collapse-1" aria-expanded="true" aria-controls="collapse-1">
Collapsible Group Item #1
</a>
</h4>
</div>
<div id="collapse-1" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="heading-1">
<div class="panel-body">
Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript">
var $template = $(".panel-default");
var hash = 1;
$(".btn-add-panel").on("click", function () {
hash++
var $newPanel = $template.clone(true).insertAfter($template);
$newPanel.find(".panel-heading").attr("id", "heading-" + hash);
$newPanel.find("a").attr("href", "#collapse-" + hash).attr("aria-controls", "collapse-" + hash).attr("class", "collapsed").attr("aria-expanded", "false")
$newPanel.find(".panel-collapse").attr("id", "collapse-" + hash).attr("aria-labelledby", "heading-" + hash).attr("aria-expanded", "false").removeClass("in");
$("#accordion").append($newPanel.fadeIn());
$("#collapse-" + hash).css({ 'height:': '0px'})
});
</script>
You could put an example in jsFiddle?
– Guilherme Nascimento