How can I attach content to dynamically created tab? if I leave a div with that id there is a mess.
- the third tab content apper in the first tab
- after I click the checkbox it looks good but in the third click (hide and show again) the third tab content dissaper.
How can I press the checkbox to show and hide the tab and and his content dynamically?
live: http://jsfiddle.net/dSxby/
html:
<div id="tabs">
<ul>
<li><a href="#tabs-1">tab 1</a>
</li>
<li><a href="#tabs-2">tab 2</a>
</li>
</ul>
<div id="tabs-1">
<table class="form-table">
<tr>
<th scope="row">
<label for="dp_add_license">Add tab</label>
</th>
<td>
<input type="checkbox" id="dp_add_license" name="dp_add_license" value="1"
/>
</td>
</tr>
</table>
</div>
<div id="tabs-2">
<p>tab 2 content.</p>
</div>
<div id="tabs-3">
<p>tab 3 content.</p>
</div>
</div>
jquery:
$(document).ready(function() {
$("#tabs").tabs();
$('#dp_add_license').click(function() {
if ($(this).is(':checked')) {
$("#tabs").tabs("add", '#tabs-3', "tab 3");
} else {
$("#tabs").tabs("remove", '#tabs-3');
}
});
});