javascript - Bootstraps Tabs, open previous/preceeding tab when closing tab -
i have following code:
function registercloseevent() { $("#tabs").on("click", ".close", function() { var tabid = $(this).parents("a").attr("href"); var uuid = $(this).parents("a").attr("data-id"); $(tabid).remove(); var tabfirst = $("#tabs a:first"); tabfirst.tab("show"); $(this).parents("li").remove(); }); }
which closing/removing current active tab , opens/activated first tab.
i want open preceding tab instead of first 1 , tried no luck on how achieve this.
any welcome
edit: html code
<ul class="nav nav-tabs" id="tabs" style="border-bottom: 1px solid rgb(221, 221, 221);"> <li class=""><a href="#tab1" data-toggle="tab"><button class="close closetab" type="button">×</button>some title</a></li> <li class=""><a href="#tab2" data-toggle="tab"><button class="close closetab" type="button">×</button>some title</a></li> <li class=""><a href="#tab8" data-toggle="tab"><button class="close closetab" type="button">×</button>some title</a></li> <li class=""><a href="#tab11" data-toggle="tab"><button class="close closetab" type="button">×</button>some title</a></li> </ul> <div class="tab-content" id="tab-content"> <div class="tab-pane" id="tab1"> </div> <div class="tab-pane" id="tab2"> </div> <div class="tab-pane" id="tab8"> </div> <div class="tab-pane" id="tab1"> </div> </div>
note #tab hrefs variable depending on how many tabs opened.
Comments
Post a Comment