2013-05-15 1 views
1

그녀는 내 기능입니다. 이 단지 생각이 아니 내가 활성 클래스여러 요소에 대해 여러 토글 추가 클래스 추가

$(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;  
      } 
    });  
}); 

중 하나를 클래스 noactive를 제거하고 추가 할 .close-hideme을 클릭하면됩니다 작업 방법 활성, 여기에 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

당신이 바이올린 그래서 우리는 또한 – ajgiv

+0

이 그것을 당신의 HTML을 살펴'.hide' 또는'.hideme'를 얻을 수 있습니다를 제공 할 수 있다면 도움이 쉬울 것? –

답변

0

HTML 없이는 말하기 어렵지만 parent() 대신 closest()을 사용해보세요.

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

.hideme 죄송합니다. 가장 잘 작동하지 않는 이유로 가장 가까운 것을 발견하지 못했습니다. –

관련 문제