简体   繁体   中英

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

I have a set of filters which are in accordions. When the user clicks on one of the filter headings, I just want to show that elements fitlers. My issue is that when I click on an element header to show the filters, all the other classes change too.

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

You should be referring the parent with "this"

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM