I need to add custom css to jquery tabs when it is selected, how?

你。 提交于 2019-12-02 09:40:17

If I don't misunderstand your question, you could simply do as following:

$('#tabs .tab-menu li a').click(function() {
    $('#tabs .tab-menu li').css('background-image', 'url("images/original-bg.png")');
    $(this).parent().css('background-image', 'url("images/tab-over.png")'; 
});

You could put the code in the select event of the tab control

$( "#tabs" ).tabs({
   select: function(event, ui) { 
     //ui.item has the current object for you.
   }
});

http://docs.jquery.com/UI/Tabs#event-select

WHOA! Way over-extending things here!

OK, First of all, jQuery is great, but it has already done the work. To do what you are trying to achieve, you don't need ANY JavaScript of any kind. Use simple CSS.

Watch:

/*  FYI: The following CSS selector can also be used to make changes 
    via JavaScript/jQuery to Currently selected tab.
    I have a blog post about that I'll list at the end of my answer */
.ui-tabs-selected {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected li element acting as the tab */

/*  If you would like to change the background or something of current panel,
    you would access it with the following CSS selector */
.ui-tabs-panel:not(.ui-tabs-hide) {
    background-image: url('images/tab-over.png') !important;
} /* This will change the background of the 
     currently selected div element acting as the panel */

As for that link I promised earlier, this blog post goes into much more depth about ez access to currently selected tabs "outside" of the "tabs events".

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