<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head profile="http://gmpg.org/xfn/11"> <title>add-remove-tabs-using-jquery</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Style-Type" content="text/css" /> <meta name="description" content="" /> <meta name="keywords" content="" /> <style> body { font-family: Verdana, Helvetica, Arial, sans-serif; font-size: 12px; } #add-tabs { padding: 5px; border: 1px solid #519e2d; margin-bottom: 20px; } /* Caution! Ensure accessibility in print and other media types... */ @media projection, screen { /* Use class for showing/hiding tab content, so that visibility can be better controlled in different media types... */ .ui-tabs-hide { display: none !important; } } /* Hide useless elements in print layouts... */ @media print { .ui-tabs-nav { display: none; } } /* Skin */ .ui-tabs-nav { list-style: none; margin: 0; padding: 0 0 0 3px; } .ui-tabs-nav:after { /* clearing without presentational markup, IE gets extra treatment */ display: block; clear: both; content: " "; } .ui-tabs-nav li { float: left; margin: 0 0 0 2px; font-weight: bold; } .ui-tabs-nav a, .ui-tabs-nav a span { float: left; /* fixes dir=ltr problem and other quirks IE */ padding: 0 12px; background: #519e2d; } .ui-tabs-nav a { margin: 5px 0 0; /* position: relative makes opacity fail for disabled tab in IE */ padding-left: 0; background-position: 100% 0; text-decoration: none; white-space: nowrap; /* @ IE 6 */ outline: 0; /* @ Firefox, prevent dotted border after click */ } .ui-tabs-nav a:link, .ui-tabs-nav a:visited { color: #fff; } .ui-tabs-nav .ui-tabs-selected a { position: relative; top: 1px; z-index: 2; margin-top: 0; background-position: 100% -23px; } .ui-tabs-nav a span { padding-top: 1px; padding-right: 0; height: 20px; background-position: 0 0; line-height: 20px; } .ui-tabs-nav .ui-tabs-selected a span { padding-top: 0; height: 27px; background-position: 0 -23px; line-height: 27px; } .ui-tabs-nav .ui-tabs-selected a:link, .ui-tabs-nav .ui-tabs-selected a:visited, .ui-tabs-nav .ui-tabs-disabled a:link, .ui-tabs-nav .ui-tabs-disabled a:visited { /* @ Opera, use pseudo classes otherwise it confuses cursor... */ cursor: text; } .ui-tabs-nav a:hover, .ui-tabs-nav a:focus, .ui-tabs-nav a:active, .ui-tabs-nav .ui-tabs-unselect a:hover, .ui-tabs-nav .ui-tabs-unselect a:focus, .ui-tabs-nav .ui-tabs-unselect a:active { /* @ Opera, we need to be explicit again here now... */ cursor: pointer; } .ui-tabs-disabled { opacity: .4; filter: alpha(opacity=40); } .ui-tabs-nav .ui-tabs-disabled a:link, .ui-tabs-nav .ui-tabs-disabled a:visited { color: #000; } .ui-tabs-panel { border: 1px solid #519e2d; padding: 10px; background: #fff; /* declare background color for container to avoid distorted fonts in IE while fading */ } /*.ui-tabs-loading em { padding: 0 0 0 20px; background: url(loading.gif) no-repeat 0 50%; }*/ /* Additional IE specific bug fixes... */ * html .ui-tabs-nav { /* auto clear @ IE 6 & IE 7 Quirks Mode */ display: inline-block; } *:first-child+html .ui-tabs-nav { /* auto clear @ IE 7 Standards Mode - do not group selectors, otherwise IE 6 will ignore complete rule (because of the unknown + combinator)... */ display: inline-block; } .hide, #dummy-0, #dummy-1, #dummy-2, #dummy-3, #dummy-4 { display: none !important; } </style> <script type="text/javascript" src="js/jquery.js?ver=1.2.6"></script> <script type="text/javascript" src="js/ui.core.js?ver=1.5.3"></script> <script type="text/javascript" src="js/ui.tabs.js"></script> <script> $(document).ready(function(){ $("#example > ul").tabs(); $(".toggle-modules input:checkbox").click(function() { $(this).blur(); // get the checkbox index var module = $(".toggle-modules input:checkbox").index($(this)); if($(this).is(':checked')) { $("#example > ul").tabs("remove", module); // remove dummy tab $("#example > ul").tabs("add", 'index.php?return=Content for '+this.value, this.value, module); // add tab and content $("#example > ul").tabs("select", module); // select the new tab } else { $("#example > ul").tabs("remove", module); // remove the tab $("#example > ul").tabs("add", '#dummy-'+module, '', module); // add the dummy tab $($("#example > ul").children("li")[module]).addClass("hide"); // hide the dummy tab //any checked checkboxes? var val = []; $(".toggle-modules input:checkbox:checked").each(function(i){ val[i] = $(".toggle-modules input:checkbox").index($(this)); }); if(val[0]==undefined) { $("#example > ul").tabs("select", 0); // select the first dummy tab? } else { $("#example > ul").tabs("select", val[0]); // select the first checked tab } } }); }); </script> </head> <body> <div id="add-tabs" class="toggle-modules"> Add/remove tabs: <input type="checkbox" class="checkbox" name="add_tab[]" value="Tab 1" id="tab_1" /> Add Tab 1 <input type="checkbox" class="checkbox" name="add_tab[]" value="Tab 2" id="tab_2" /> Add Tab 2 <input type="checkbox" class="checkbox" name="add_tab[]" value="Tab 3" id="tab_3" /> Add Tab 3 <input type="checkbox" class="checkbox" name="add_tab[]" value="Tab 4" id="tab_4" /> Add Tab 4 <input type="checkbox" class="checkbox" name="add_tab[]" value="Tab 5" id="tab_5" /> Add Tab 5 </div> <div id="example" class="flora"> <ul> <li><a class="hide" href="#dummy-0"></a></li> <li><a class="hide" href="#dummy-1"></a></li> <li><a class="hide" href="#dummy-2"></a></li> <li><a class="hide" href="#dummy-3"></a></li> <li><a class="hide" href="#dummy-4"></a></li> </ul> <div class="hide" id="dummy-0"></div> <div class="hide" id="dummy-1"></div> <div class="hide" id="dummy-2"></div> <div class="hide" id="dummy-3"></div> <div class="hide" id="dummy-4"></div> </div> </body> </html>