I have an aspx page on which I have 2 static jquery tabs.Upon clicking on a button avaiable on one of these tabs,I would like to add a new tab dynamically,which gets its content loaded from another aspx page.I've also tried with the following sample
http://jquery-ui.googlecode.com/svn/trunk/demos/tabs/manipulation.html
I've downloaded jquery-ui-1.8rc3.custom zip file and tried to add the above page with the relevant script,css files to my asp.net website and run,but it does not seem to work.Also I do not want to have a dialog opening and asking the user to enter the tab title as in the above sample.
Please could someone help me with this?
Thanks.
Tabs can be added dynamically by passing array of items and index value to the addTab method. // New tab title and content inputs are fetched and stored in local variable let title: string = document. getElementById('tab-title').
To make the tabs toggleable, add the data-toggle="tab" attribute to each link. Then add a . tab-pane class with a unique ID for every tab and wrap them inside a div element with class .
Have you tried using the add method of the tabs?
var tabs = $("#tabs").tabs();
$('#tabs-1 button').click(function(){
tabs.tabs('add','/url_for_tab/','New tab');
});
Update -- As of jQuery UI 1.9 the add remove methods have been deprecated and in jQuery UI 1.10 they have been removed.
The correct way to do this for remote (ajax) content tabs now is:
var tabs = $( "#tabs" ).tabs();
var ul = tabs.find( "ul" );
$( "<li><a href='/url_for_tab/'>New Tab</a></li>" ).appendTo( ul );
tabs.tabs( "refresh" );
And for when you already have the content:
var tabs = $( "#tabs" ).tabs();
var ul = tabs.find( "ul" );
$( "<li><a href='#newtab'>New Tab</a></li>" ).appendTo( ul );
$( "<div id='newtab'><p>New Content</p></div>" ).appendTo( tabs );
tabs.tabs( "refresh" );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With