Danzel
Danzel

Reputation: 41

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");
            });

Upvotes: 0

Views: 83

Answers (1)

Sonia
Sonia

Reputation: 1919

You should be referring the parent with "this"

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

Upvotes: 1

Related Questions