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');
});
CodePudding user response:
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');
});
CodePudding user response:
You can target the description tab link using this line.
$('a[href="#tab-description"]').trigger('click')
