function bootstrapTabControl(){ const items = $('.nav-link'); const pane = $('.tab-pane'); const itemsLength = items.length; // next $('.nexttab').on('click', () => { let activeIndex; for(let i = 0; i < itemsLength; i++){ if(items.eq(i).hasClass('active')){ activeIndex = i; break; } } if(activeIndex < itemsLength - 1){ // for tab items.eq(activeIndex).removeClass('active'); items.eq(activeIndex + 1).addClass('active'); // for pane pane.eq(activeIndex).removeClass('show active'); pane.eq(activeIndex + 1).addClass('show active'); } location.hash = items.eq(activeIndex + 1).attr("href"); }); // Prev $('.prevtab').on('click', () => { let activeIndex; for(let i = 0; i < itemsLength; i++){ if(items.eq(i).hasClass('active')){ activeIndex = i; break; } } if(activeIndex !== 0){ // for tab items.eq(activeIndex).removeClass('active'); items.eq(activeIndex - 1).addClass('active'); // for pane pane.eq(activeIndex).removeClass('show active'); pane.eq(activeIndex - 1).addClass('show active'); } location.hash = items.eq(activeIndex - 1).attr("href"); }); } bootstrapTabControl(); const topFunction = () => { document.body.scrollTop = 0; // For Safari document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera } topFunction();