簡體   English   中英

在單擊時,僅將類應用於單擊的元素,而不是將所有元素都應用於同一類

[英]On click only apply class to element clicked, not all elements with the same class

我有一組手風琴式的過濾器。 當用戶單擊過濾器標題之一時,我只想顯示該元素適合。 我的問題是,當我單擊元素標題以顯示過濾器時,所有其他類也會更改。

            $('.filter-group__title').on('click', function () {
                $(".glyphicon").toggleClass("glyphicon-minus glyphicon-plus");
            });

您應該用“ this”來指代父母

$('.filter-group__title').on('click', function () {
    $(this).find(".glyphicon").toggleClass("glyphicon-minus glyphicon-plus");
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM