2014-07-18 10 views
0

나는 아주 멋진 아코디언을 가지고 있습니다.이 글꼴은 멋진 글꼴로 .fa-angle-down으로 추가되었습니다.Jquery Accordion이 클릭 할 때 Fontawesome 아이콘을 변경합니다.

toggleClass를 추가 했으므로 .accordion-toggle을 클릭하면 아이콘 180이 아래쪽이 아닌 위로 향하도록 회전합니다.

내가 도움이 필요한 것은 다른 .accordion-toggle에 .rotate180 클래스가있는 경우 다음 비트를 추가하는 것입니다.

나는 this-

$(".fa-angle-down").not($(this)).removeClass('rotate180'); 

을 시도했지만 그것은 단지 모든 ... 도움말에서 클래스를 제거? 내가 무엇을 목표로 .find 사용되지 않았다 -

답변

1

그냥 다음 클래스를 가지고있는 모든 여기

$("#accordion").accordion(); 

$('#accordion .accordion-toggle').click(function() { 

    // Whatever other code here too 

    //Remove all rotate180 
    $('.rotate180').removeClass('rotate180'); 
    //Now just add it for 'this' 
    $(this).children('.fa-angle-down').addClass('rotate180'); 
}); 

근무 데모처럼 제거 찾기 내가 필요.

$(document).ready(function($) { 
$('#accordion').find('.accordion-toggle').click(function(){ 

$(this).next().slideToggle('fast'); 
$(this).toggleClass('active'); 
$(this).find('.fa-angle-down').toggleClass('rotate180'); 

$(".accordion-content").not($(this).next()).slideUp('fast'); 
$(".accordion-toggle").not($(this)).removeClass('active'); 
$(".accordion-toggle").not($(this)).find('.fa-angle-down').removeClass('rotate180'); 

}); 
    }); 
+0

위의 예와 동일한 문제가 있습니다. 열려고 클릭 한 모든 항목을 닫습니다. 클릭 한 것 이외의 모든 인스턴스를 대상으로 지정해야합니다. –

+0

자바 스크립트 코드를 모두 게시하십시오. 코드의 나머지 부분에서 '시도한 부분'을 볼 수 없습니까? –

+0

안녕하세요 롭, 만약 당신이 또 다른 모습을 쓴다면 "나는 이것을 시험해 봤어."라고 쓰고 코드 줄을 그었다. 그래서 모든 자바 스크립트를 게시했습니다. –

0

http://jsfiddle.net/md3hd/ 그것을 밖으로 근무 :

$(document).ready(function($) { 
    $('#accordion').find('.accordion-toggle').click(function(){ 

    $(this).next().slideToggle('fast'); 
    $(this).toggleClass('active') 
    $(".fa-angle-down").toggleClass('rotate180') 

    $(".accordion-content").not($(this).next()).slideUp('fast'); 
    $(".accordion-toggle").not($(this)).removeClass('active'); 

    }); 
    }); 
관련 문제