jQuery tabs . . . how do I change the css of a tab?

*爱你&永不变心* 提交于 2019-12-08 22:13:42

Add a select or load handler (depending on when you want it to fire) that adds the CSS or class to the component that you want to change.

 var $tabs = $('#tabs').tabs({
                 event: 'mouseover',
                 select: function(event,ui) {
                             $(ui.panel).css({ backgroundColor: '#ffffff'});
                         });
             });

It might be easier to just use the existing classes for the tabs, though, and adjust the CSS for the tab container.

#tabs .ui-state-highlight {
    background-color: #ffffff;
}

#tabs .ui-state-active {
    background-color: #ff0000;
    color: #ffffff;
}

#tabs .ui-state-default {
    background-color: #ffff00;
    color: #000000;
}
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content

This will change the class on your item.

You can find information about that here:

http://www.sohtanaka.com/web-design/simple-tabs-w-css-jquery/

If you using Firefox with Firebug extension, you can inspect the live page element, to see what class it currently have.

In your code, the element with class basictab is the tabs parent div. Your code will change it's class. If you want to change only the current active class, inspect it using Firebug. Current jQuery-UI implementation will change the selected li class to have class ui-tabs-selected.

If you purpose to change the element's class is to apply the css, maybe it's simpler for you to create css for ui-tabs-selected class, instead to change it, since it will make you write extra js code only for something that can be done with css alone.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!