2013-06-28 40 views
0

我得到了這個jQuery代碼,我發現當我點擊標題時,它突出顯示紅色。我現在的問題是去除加亮的顏色,只強調被點擊的當前或最近一個想要刪除突出顯示的標題時點擊當前標題id

$j('div.tabbed-sidebar ul.sidebar-tabs li a').click(function() { 
     $j(this).css('background-color', 'red'); <---this is where is highlights red 
     $j(this).removeClass('tab-current'); 
     var thisClass = this.className.substring(12, this.className.length); 
     var parentId = this.parentNode.parentNode.parentNode.id; 
     $j('#' + parentId + '.tabbed-sidebar div.sidebar-tab-content').hide(); 
     $j('#' + parentId + '.tabbed-sidebar div.sidebar-tab-content-' + thisClass).show(); 
     $j('#' + parentId + '.tabbed-sidebar ul.sidebar-tabs li a').removeClass('tab-current'); 
     $j(this).addClass('tab-current');  
    }); 
+1

請您縮小代碼的相關部分,創建一個演示和講解更好。 –

回答

0

這裏是你如何能做到這一點:

fiddle example

的.js

$("h2").on("click",function(){ 
    $(this).addClass("red"); 
    $("h2").not(this).removeClass("red"); 
}); 

.css

.red{ 
    background: red; 
} 

的.html

<h2>header</h2> 
<h2>header</h2> 
<h2>header</h2> 
<h2>header</h2> 
<h2>header</h2> 
相關問題