Reputation: 11487
I am using the jquery ui tabs to create dynamic tabs on the fly which will start off without any content. From what I can tell my code is building everything and putting it in the proper places, but jquery is not recognizing them as tabs. How would I get it to recognize the new tabs that were created after page load?
The html code:
<div class="main">
<div>
<button id="new">button</button>
</div>
<div id="tabs">
<ul>
<li><a href="#tabs-1">View1</a></li>
<li><a href="#tabs-2">View2</a></li>
<li id="createView"><a href="null">Create New</a></li>
</ul>
<div id="tabs-1">
<p>something on this page</p>
</div>
<div id="tabs-2">
<div>
<p>something else on this page</p>
</div>
</div>
</div>
</div>
the Javascript:
//Tabs functionality
$('#tabs').tabs();
//Create new view
var tabNum = 3;
$('#new').click(function() {
$('#tabs ul').append('<li>' + '<a href="' + '#tabs-' + tabNum + '">' + 'newitem' + '</a>' + '</li>');
$('#tabs').append('<div id="' + 'tabs-' + tabNum + '">' + '<div>new</div>' + '</div>');
var NewViewNum = 'tabs-' + tabNum;
$(NewViewNum).focus();
tabNum++;
});
Upvotes: 0
Views: 1501
Reputation: 4024
The jQuery UI Tabs have a refresh
method you can use per the documentation.
Try calling:
$("#tabs").tabs("refresh");
Upvotes: 3