WEB/jQuery

슬라이드 토글시 단순 텍스트 비교말고 attr 이용

연꽃- 2020. 1. 17. 17:51

$(".content-bar").click(function () {
        $(".content-bottom").slideToggle(600);
        
        var text = "이전 컨텐츠 더보기    ";
        if($(this).attr("openMoreCotent") == undefined) {
         text += "▲";
         $(this).attr("openMoreCotent", "open");
        } else {
         text += "▼";
         $(this).removeAttr("openMoreCotent");
        }
        
        $(this).text(text);
    });