yorkmyers priority asked 2 years ago


Is it possible to set the default tab to not be the first one, using standard (vanilla) JavaScript?

I found this page, but it's only for Angular

I'm able to programmatically change the tab upon page load with this code:

<script type="text/javascript">     
    $(function() {
        const triggerEl = document.querySelector('#mytabs a[href="#specific-tab"]');
        mdb.Tab.getInstance(triggerEl).show(); // Select tab by name
    });
</script>

However the screen briefly flashes the contents of the first tab.

I also tried changing the placement of the "active" class in the LI, but that only changes the tab selected and not the contents.

Thank you!


Kamila Pieńkowska staff answered 2 years ago


You need to change the active state for the tab and for content. Example snippet: https://mdbootstrap.com/snippets/standard/kpienkowska/4221547


yorkmyers priority commented 2 years ago

Perfect, thank you!!



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Priority
  • Premium support: Yes
  • Technology: MDB Standard
  • MDB Version: MDB5 3.11.0
  • Device: Desktop
  • Browser: Chrome
  • OS: Windows
  • Provided sample code: No
  • Provided link: Yes