Search code examples
twitter-bootstrapbootstrap-4tabsbootstrap-5

How do I fix dynamic tab selection after upgrading from Bootstrap V4 to V5?


After upgrading from Bootstrap V4 to V5, the following dynamic tab selection code stopped working.

var v_screen = 3;
var triggerMap = {
        2: '#open-tab',
        3: '#closed-tab',
        4: '#support-tab',
        5: '#other-tab'
    };
    $(triggerMap[v_screen]).trigger('click');

Solution

  • As per https://github.com/twbs/bootstrap/issues/34767 use the following code

    bootstrap.Tab.getOrCreateInstance($(triggerMap[v_screen])).show();
    

    instead of

    $(triggerMap[v_screen]).trigger('click');