2013-05-15 110 views
1

她是我的功能。有隻認爲它不工作是當我點擊.close-hideme我想刪除類noactive並添加類活躍不同元素的多個切換添加刪除類

$(function() {  
    var text = $(this).text(); 
    $(".hideme").hide();  
    var elements = $(".bold_blue, .bold_blue_img");  
    elements.click(function() { 
      var element = $(this); 
      elements.removeClass("active"); 
      if (text == 'dot' || text == '+' && !$(".hideme").is(":visible")) { 
        $(this).closest('tr').find(".bold_blue_img").text($(this).closest('tr').find(".bold_blue_img").text() == '-' ? '+' : '-');  
        $(this).closest('tr').find(".bold_blue_img").removeClass("active").addClass("noactive"); 
        return false; 
      }  
      else {  
        $(this).parents("tr").next().slideToggle("slow");  
        $(this).closest('tr').find(".bold_blue_img").text($(this).closest('tr').find(".bold_blue_img").text() == '-' ? '+' : '-'); 
        $(this).closest('tr').find(".bold_blue_img").toggleClass('noactive');  
        return false; 
      } 
    }); 
    $('.close-hideme').bind('click', function() {  
      if (!$(".hideme").is(":visible")) { 
        $(this).closest('tr').find(".bold_blue_img").removeClass("noactive").addClass("active");  
        $(this).parents(".hideme").hide("slow"); 
        return false;  
      } 
    });  
}); 

任何一個有想法如何該類改變爲主動,這裏的html代碼

<table style="width:100%"> 
<tbody> 
<tr class="parent"> 
    <td><a class="bold_blue">dot</a><a class="bold_blue_img active">+</a> 
    <!-- i've to use 2 different hrefs here plus is text only but inside css there is class active and noactive with background images --> 
    </td> 
</tr> 
<tr class="hideme"> 
    <td><a class="close-hideme right">X</a> 
    <!-- this button is not working, i mean is hiding but is not changing bold_blue_img class to active --> 
</td> 
    </tr> 
</tbody> 
</table>  
+1

它會更容易幫助,如果你能提供一個小提琴,所以我們還可以得到一看你的HTML – ajgiv

+0

是吧'.hide'或'.hideme'? –

回答

0

這很難說沒有HTML,但試試這個(closest()而不是parent())。

$(this).closest('tr').find(".bold_blue_img").removeClass("noactive").addClass("active"); 
+0

.hideme對不起,我沒有發現, 最近由於某種原因不工作以及 –