How to add a close icon in bootstrap tabs?

前端 未结 3 2078
耶瑟儿~
耶瑟儿~ 2021-01-31 10:39

I want to add a close icon in bootstrap tabs and then I can close the tab by click the icon.

I try below but the \"X\" is displayed not on the same line as tab title.

3条回答
  •  孤城傲影
    2021-01-31 10:55

    Small tweaks to Vinod Louis's answer - relative link to the li list and only show a tab if it is the current one closing.

    function close_tab (tab_li)
    {
        var tabContentId = $(tab_li).parent().attr("href");
        var li_list = $(tab_li).parent().parent().parent();
        $(tab_li).parent().parent().remove(); //remove li of tab
        if ($(tabContentId).is(":visible")) {
            li_list.find("a").eq(0).tab('show'); // Select first tab
        }
        $(tabContentId).remove(); //remove respective tab content
    }
    

    Then attach:

    $(".closeTab").click(close_tab(this));
    

    Or:

    
    

提交回复
热议问题