I have an accordion where I'm dynamically creating new elements. However, when I do I cannot seem to get the newest element to default to open. It's always the first element.
Ideas?
Here's the HTML:
<asp:MultiView ID="MainView" runat="server">
<asp:View ID="View1" runat="server">
<table style="width: 100%; border-width: 3px; border-color: #C4F691; border-style: solid">
<tr>
<td>
<div class="rowClassSpace">
</div>
<div id="accordion">
<a href="#">Make/Model (Insured Vehicle)</a>
<div>
<p>
Content
</p>
</div>
</div>
<div>
<button id="addAccordion">
Add Another Vehicle</button>
</div>
</td>
</tr>
</table>
</asp:View>
</asp:MultiView>
Here's the JS:
// Initialize accordion
$(document).ready(function () {
$(function () {
$("#accordion").accordion();
});
});
// Adding according sections
$('#addAccordion').click(function () {
});
function addAccordion() {
var active = $('#accordion').accordion('option', 'active');
$('#accordion').append('<a href="#">Make/Model (Other Car #)</a><div><p>New data</p></div>').accordion('destroy').accordion({ active: active});
}