Remove a tab from tab panel in JavaScript
Description
The following code shows how to remove a tab from tab panel.
Example
<!--from w w w . j a v a 2 s. com-->
<!doctype html>
<html lang="en">
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
<link type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/themes/smoothness/jquery-ui.css" rel="stylesheet" />
<script type="text/javascript">
$(function(){
//create the tabs
$("#tabs").tabs();
//add click handler for 'remove' button
$("#remove").click(function() {
//get the index to remove
var indexNumber = $("#indexNum").val() - 1;
//remove the tab
$("#tabs").tabs("remove", indexNumber);
});
//add click handler for 'add' button
$("#add").click(function() {
//define tab label
var newLabel = "A New Tab!"
//add the new tab
$("#tabs").tabs("add", "#newTab", newLabel);
});
});
</script>
</head>
<body>
<label>Enter a tab index number to remove:</label><input id="indexNum"><button id="remove">Remove!</button><br><br>
<button id="add">Add a new tab!</button><br><br>
<div class="demo">
<div id="tabs">
<ul>
<li><a href="#tabs-1">Nunc tincidunt</a></li>
<li><a href="#tabs-2">Proin dolor</a></li>
<li><a href="#tabs-3">Aenean lacinia</a></li>
</ul>
<div id="tabs-1">
<p>Proin elit arcu, rutrum commodo, vehicula tempus, commodo a, risus. Curabitur nec arcu. Donec sollicitudin mi sit amet mauris. Nam elementum quam ullamcorper ante. Etiam aliquet massa et lorem. Mauris dapibus lacus auctor risus. Aenean tempor ullamcorper leo. Vivamus sed magna quis ligula eleifend adipiscing. Duis orci. Aliquam sodales tortor vitae ipsum. Aliquam nulla. Duis aliquam molestie erat. Ut et mauris vel pede varius sollicitudin. Sed ut dolor nec orci tincidunt interdum. Phasellus ipsum. Nunc tristique tempus lectus.</p>
</div>
<div id="tabs-2">
<p>Morbi tincidunt, dui sit amet facilisis feugiat, odio metus gravida ante, ut pharetra massa metus id nunc. Duis scelerisque molestie turpis. Sed fringilla, massa eget luctus malesuada, metus eros molestie lectus, ut tempus eros massa ut dolor. Aenean aliquet fringilla sem. Suspendisse sed ligula in ligula suscipit aliquam. Praesent in eros vestibulum mi adipiscing adipiscing. Morbi facilisis. Curabitur ornare consequat nunc. Aenean vel metus. Ut posuere viverra nulla. Aliquam erat volutpat. Pellentesque convallis. Maecenas feugiat, tellus pellentesque pretium posuere, felis lorem euismod felis, eu ornare leo nisi vel felis. Mauris consectetur tortor et purus.</p>
</div>
<div id="tabs-3">
<p>Mauris eleifend est et turpis. Duis id erat. Suspendisse potenti. Aliquam vulputate, pede vel vehicula accumsan, mi neque rutrum erat, eu congue orci lorem eget lorem. Vestibulum non ante. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Fusce sodales. Quisque eu urna vel enim commodo pellentesque. Praesent eu risus hendrerit ligula tempus pretium. Curabitur lorem enim, pretium nec, feugiat nec, luctus a, lacus.</p>
<p>Duis cursus. Maecenas ligula eros, blandit nec, pharetra at, semper at, magna. Nullam ac lacus. Nulla facilisi. Praesent viverra justo vitae neque. Praesent blandit adipiscing velit. Suspendisse potenti. Donec mattis, pede vel pharetra blandit, magna ligula faucibus eros, id euismod lacus dolor eget odio. Nam scelerisque. Donec non libero sed nulla mattis commodo. Ut sagittis. Donec nisi lectus, feugiat porttitor, tempor ac, tempor vitae, pede. Aenean vehicula velit eu tellus interdum rutrum. Maecenas commodo. Pellentesque nec elit. Fusce in lacus. Vivamus a libero vitae lectus hendrerit hendrerit.</p>
</div>
</div>
</div>
</body>
</html>
The code above generates the following result.
Javascript Tutorial Tab
Add a tab to tab panel in JavaScript
Alert the id of the tab that was selected i...
Build jQuery UI Tabs - Collapse content in ...
Build jQuery UI Tabs - Default functionalit...
Build jQuery UI Tabs - Open on mouseover in...
Build jQuery UI Tabs - Simple manipulation ...
Build jQuery UI Tabs - Sortable in JavaScri...
Build jQuery UI Tabs - Tabs at bottom in Ja...
Build jQuery UI Tabs - Vertical Tabs functi...
Destroy a tab panel in JavaScript
Enable and disable tab by click a button in...
Handle Tab selected event in JavaScript
Set second tab selected and disable the fir...
Set tab to be not always Open and not auto ...
Set tab to fill Space in JavaScript
Set up Animation for tab on change event in...
Add a tab to tab panel in JavaScript
Alert the id of the tab that was selected i...
Build jQuery UI Tabs - Collapse content in ...
Build jQuery UI Tabs - Default functionalit...
Build jQuery UI Tabs - Open on mouseover in...
Build jQuery UI Tabs - Simple manipulation ...
Build jQuery UI Tabs - Sortable in JavaScri...
Build jQuery UI Tabs - Tabs at bottom in Ja...
Build jQuery UI Tabs - Vertical Tabs functi...
Destroy a tab panel in JavaScript
Enable and disable tab by click a button in...
Handle Tab selected event in JavaScript
Remove a tab from tab panel in JavaScript
Rotate tabs in JavaScriptSet second tab selected and disable the fir...
Set tab to be not always Open and not auto ...
Set tab to fill Space in JavaScript
Set up Animation for tab on change event in...