You can get the attribute rel
and split it to get the last number to use for the active_level_
class. We can also pull $(this)
into a variable now since its being used more than once.
$(document).on("click", "a.tabPagination", function(){
var tab = $(this);
$('.current').removeAttr('class');
$('#tabs li[class!="current"]').hide();
$('#' + tab.attr('rel')).show();
for (var i = 1; i <= 6; i++)
$('#tower').removeClass('active-level-' + i);
$('#tower').addClass('active_level_' + tab.attr('rel').split('-')[1]);
});
tab.attr('rel').split('-')[1]
will get the tab's rel
attribute, split the string into two at the -
character using split()
and get the second part to return the number we want.