简体   繁体   中英

How to add a “selected” class to a selected tab anchor using jQuery UI Tabs?

I'm using jQuery UI tabs(). It adds "ui-tabs-selected" to the selected LI, but each LI has an ID because it's different. Due to the multi ID/class bug in IE6, I need to apply a "selected" class to the anchor that is inside the "ui-tabs-selected" LI.

Can someone tell me how to do this?

you can do

$('li.ui-tabs-selected a').addClass('yourclass');

To manually add a class to any of the tabs you can do assuming your ul has the id #tabs

$('#tabs li a').eq(1).addClass('yourclass'); //this will add class to second tab

Updated Answer Use the select event to trigger addClass()

$('#wrap').tabs({
    select: function(event, ui) {
        $(this).find('li a').removeClass('myclass').eq(ui.index).addClass('myclass')
    }
});

Check working example at http://jsfiddle.net/6JryL/

$('.ui-tabs-selected a').addClass('selected');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM