Home  »  CodeSnippets   »   Trigger a Tab on Button Click in Bootstrap 5

Trigger a Tab on Button Click in Bootstrap 5

Posted: February 8, 2022 | by Michael Bright

$('.select-buttons__wrapper a').each(function(){
   $(this).on('click', function(e){
      e.preventDefault();
      var tabEle = $(this).attr('href');
      $(tabEle).siblings().removeClass('active').removeClass('show');
      $(tabEle).addClass('active show');
      var relativeLink = $('[href="'+tabEle+'"');
      relativeLink.parent().siblings().find('a').removeClass('active');
      relativeLink.addClass('active');
   })
});

Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.