skip to Main Content

On my single product page I have button where I want to open default product tab named "description" on click on specific button with id="cely-popis". This should perform only when another tab is active than "decription".

$("#cely-popis").click(function() {
    $('html, body').animate({
        scrollTop: $("#tab-description").offset().top - 64
    }, 2000);

    $('.nav-link[href=tab-description]').trigger('click');
});

2

Answers


  1. Chosen as BEST ANSWER

    I found a solution:

    $('#cely-popis').click(function(e) {
        e.preventDefault();
        
        // smooth scroll to section
        $('html, body').animate({
            scrollTop: $('#tabs-container').offset().top - 32
        }, 2000);
    
        // add "active" class
        $('.wc-tabs li a').each(function() {
            if ($(this).hasClass('active')) {
                $(this).removeClass('active');
            }
        }); 
    
        $('.wc-tabs li#tab-title-description a').addClass('active');
        $('#tab-description').addClass('active');
        $('.woocommerce-Tabs-panel').css('display', 'none');
        $('#tab-description').css('display','block');
    });
    

  2. You can target the description tab link using this line.

    $('a[href="#tab-description"]').trigger('click')
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search