• All geek questions in one place

    Active tab management in bootstrap

    I made tabs in bootstrap.

    <div class="tabbable tabs-left"> <ul class="nav nav-tabs"> <li><a href="#menu23" data-toggle="tab">Beethoven</a></li> <li><a href="#menu24" data-toggle="tab">Bach</a></li> </ul> <div class="tab-content"> <div class="tab-pane" id="menu23"> item1 </div> <div class="tab-pane" id="menu24"> item2 </div> </div> 

    I want to activate item1 or item2 with a button or some action.

    How can i do this?

    +4
    jquery twitter-bootstrap
    whitebear Aug 2 '13 at 17:40
    source share
    2 answers

    using the boot buttons to go to the next | Previous

     <div class="btn-group"> <button class="btn" id="prevtab" type="button">Prev</button> <button class="btn" id="nexttab" type="button">Next</button> </div> 

    then in your javascript just add

     var $tabs = $('.tabbable li'); $('#prevtab').on('click', function() { $tabs.filter('.active') .prev('li') .find('a[data-toggle="tab"]') .tab('show'); }); $('#nexttab').on('click', function() { $tabs.filter('.active') .next('li') .find('a[data-toggle="tab"]') .tab('show'); }); 
    +5
    Mike ramsey Aug 2 '13 at 17:57
    source share

    You can use $ (selector) .tab ('show'); bootstrap writes about this in the documentation at http://getbootstrap.com/javascript/ . Check out my example here.

    Update:

    If you want it to be more dynamic when you create your buttons automatically. Example here

     $(document).ready(function() { $.each($("#tabs li a"), function(key, elm){ $("#buttons").append( $("<a/>") .text($(elm).text()) .addClass("btn") .click(function() { $(elm).tab('show'); }) ); }); }); 
    +1
    Konstig Aug 2 '13 at 17:46
    source share

    Source: https://habr.com/ru/post/1495003/

    More articles:

    • I18N / Angular JS / Javascript Text - javascript
    • Setting up an angularjs i18n project - javascript
    • Does Android delete cache files on external storage? - android
    • ios Facebook Log Out completely leaves safari stores data - logging
    • jQuery: subscripts of xml object names - javascript
    • How to find unique selectors for elements on pages with ExtJS for use with Selenium? - xpath
    • Angular Radio Values ​​in ng-repeat - javascript
    • Xpath to select html id including random number - html
    • Deserialize a JSON string with a variable number of elements - json
    • Backend and MVC Interface - django

    All Articles

    Geek Questions | 2019