skip to Main Content

I have an active active tab and would like to know the syntax to check if it is active.

 <ul class="nav nav-tabs" id="myTab" role="tablist">
    <li class="nav-item" role="presentation">
      <button class="nav-link active" id="personnelBtn" data-bs-toggle="tab" data-bs-target="#personnel-tab-pane" type="button" role="tab" aria-controls="home-tab-pane" aria-selected="true">
        <i class="fa-solid fa-person fa-lg fa-fw"></i><span class="d-none d-sm-block">Personnel</span>
      </button>
    </li>

2

Answers


  1. To check if the tab with ID personnelBtn is active, you can use JavaScript:

    const personnelTab = document.querySelector('#personnelBtn');
    
    if (personnelTab.classList.contains('active')) {
      console.log('The tab is currently active');
    } else {
      console.log('The tab is not active');
    }
    
    Login or Signup to reply.
  2. you can choose as below

    $('.nav-link.active')
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search