Reputation: 1287
This is the pen I'm working on and the Jqueryis below.As I want a tab style like each button shows the desire content.
Jquery
$('.content-canvas').find('div').hide();
$('.content-canvas div:first-child').show();
$('.tab-button span:first-child').addClass('active');
$('.tab-button').find('span').click(function(){
$('.tab-button').find('span').removeClass('active');
$(this).addClass('active');
var currentclass=$('.active').attr('class');
$('.content-canvas').find('div').each(function(){
if($(this).attr('class')==currentclass)
{
$('.content-canvas').find('div').hide();
$(this).show();
}
else
{
$(this).hide();
}
});
});
Upvotes: 0
Views: 99
Reputation: 7664
You are missing dot in front of class active
var currentclass = $('.active').attr('class');
Also, if you do alert(currentclass)
it will show you that it says something like "content2 active". Probably not what you expect. You could go with data-name="content2"
. And then you select with:
var currentname = $('.tab-button .active').data('name');
$('.content-canvas [data-name="'+currentname+'"]').show().siblings().hide();
Upvotes: 1