Skip to main content
Print

Script to open a specific tab from the menu click in Divi 5


// //Link to specific Tab
(function($) {
    $(document).ready(function() {
        
        function handleTabAndScroll(hash) {
            if (!hash) return;

            var $targetTabContent = $(hash);
            
           
            if ($targetTabContent.length && $targetTabContent.hasClass('et_pb_tab')) {
                var $tabsContainer = $targetTabContent.closest('.et_pb_tabs');
                
                
                var tabIndex = $targetTabContent.index();
                var $navItems = $tabsContainer.find('.et_pb_tabs_controls li');
                var $activeNavItem = $navItems.eq(tabIndex);

                
                if (!$activeNavItem.hasClass('et_pb_tab_active')) {
                    $activeNavItem.find('a').trigger('click');
                }

                setTimeout(function() {
                    var offset = 120; 
                    $('html, body').stop().animate({
                        scrollTop: $tabsContainer.offset().top - offset
                    }, 1000, 'swing'); 
                }, 400);
            }
        }

        
        if (window.location.hash) {
            
            setTimeout(function() {
                handleTabAndScroll(window.location.hash);
            }, 500);
        }

        
        $(window).on('hashchange', function() {
            handleTabAndScroll(window.location.hash);
        });

        
        $('a[href*="#"]').on('click', function(e) {
            var url = new URL(this.href);
            var hash = url.hash;
            if (hash === '#current' || hash === '#dominican' || hash === '#oldjrnl') {
                
                if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
                    e.preventDefault();
                    handleTabAndScroll(hash);
                    
                    history.pushState(null, null, hash);
                }
            }
        });
    });
})(jQuery);
// end for custom tab

Table of Contents