Twitter Bootstrap accordion icon doesnt change

前端 未结 5 1272
借酒劲吻你
借酒劲吻你 2020-12-13 20:50

I have this accordion thing from bootstrap. The arrow icons point down.

\"enter

5条回答
  •  旧时难觅i
    2020-12-13 21:36

    Using jquery.js 1.10.2 and bootstrap-collapse.js v2.3.0, this is a rehash of the above. Upon loading the document, it collapses all items but the first one and then handles susequent show/hide events.

    $(document).ready(function () {
    
        $(".accordion-body").on("shown", function (evt) {
            setIcon(evt.target, true);
        });
    
        $(".accordion-body").on("hidden", function (evt) {
            setIcon(evt.target, false);
        });
    
        $(".accordion-body").collapse("hide");
        $("#collapse-faq-1").collapse("show");
    });
    
    function setIcon(acdBody, isShown) {
        var indicator = "indicator" + acdBody.id.substr(acdBody.id.lastIndexOf("-"));
    
        if (!isShown) {
            $("#" + indicator).removeClass("icon-chevron-up").addClass("icon-chevron-down");
        } else {
            $("#" + indicator).removeClass("icon-chevron-down").addClass("icon-chevron-up");
        }
    }
    

    HTML:

    Answer 1 ...
    Answer 2 ...

提交回复
热议问题