Question

$(document).ready(function() {
    var activeTab = $('#tabs menu.active');
    var prevTab = activeTab.closest('.menu').prev();
    var nextTab = activeTab.closest('.menu').next();
    prevTab.addClass('prev');
    nextTab.addClass('next');

});

http://jsfiddle.net/qS4LN/

It doesn't seem to work, what am I doing wrong? I need to addClass prev and next to the tabs around the active tab.

Was it helpful?

Solution

You're missing the first period on your selector. Your code is:

var activeTab = $('#tabs menu.active');

menu is a class and needs it's own period. Change the code to:

var activeTab = $('#tabs .menu.active');

OTHER TIPS

updated jsfiddle

$(document).ready(function() {
    var activeTab = $('#tabs ul.menu.active');
    var prevTab = activeTab.closest('.menu').prev();
    var nextTab = activeTab.closest('.menu').next();
    prevTab.addClass('prev');
    nextTab.addClass('next');

});

You are missing a dot on 2nd line selector, change var activeTab = $('#tabs menu.active'); to var activeTab = $('#tabs ul.menu.active');

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top