У меня есть панель вкладок, использующая jQuery, и все работает правильно, кроме ссылки с data-anchor
внутри содержимого вкладки, которую следует переключить на конкретную вкладку.Переключение вкладок работает, но содержимое вкладок не отображается.
Как это исправить?
HTML:
<div class="tab-panels">
<ul class="tabs">
<li class="active" rel="panel1">panel1</li>
<li rel="panel2" id="custpanel2">panel2</li>
<li rel="panel3">panel3</li>
<li rel="panel4">panel4</li>
</ul>
<div class="panel active" id="panel1">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="panel" id="panel2">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="panel" id="panel3">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</div>
<div class="panel" id="panel4">Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
<a href="custpanel2" data-anchor="#custpanel2">
Click here
</a>
</div>
</div>
JS:
$('.tab-panels .tabs li').on('click', function(){
var $panel = $(this).closest('.tab-panels');
$panel.find('.tabs li.active').removeClass('active');
$(this).addClass('active');
var panelToShow = $(this).attr('rel');
$panel.find('.panel.active').fadeOut(300, showNextPanel);
function showNextPanel(){
$(this).removeClass('active');
$('#'+panelToShow).fadeIn(300, function(){
$(this).addClass('active');
})
}
});
//Link inside tab content
$('[data-anchor="#custpanel2"]').on('click', function(e){
e.preventDefault();
var $panel = $(this).closest('.tab-panels');
$panel.find('.tabs li.active').removeClass('active');
$('.tabs li:nth-child(3)').addClass('active');
var panelToShow = $(this).attr('rel');
$panel.find('.panel.active').fadeOut(300, showNextPanel);
function showNextPanel(){
$(this).removeClass('active');
$('#'+panelToShow).fadeIn(300, function(){
$(this).addClass('active');
})
}
});