简体   繁体   English

在单击时,仅将类应用于单击的元素,而不是将所有元素都应用于同一类

[英]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" 您应该用“ this”来指代父母

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有相同类的多个元素,仅获取单击元素的文本 - Multiple elements with the same class, get the text of only the clicked element 对于具有相同类的多个元素,仅影响jquery中的单击元素 - affect only the clicked element in jquery for multiple elements with same class 仅选择单击元素的“此”对象(而不选择同一类中的其他元素) - Select 'this' object of clicked element only (not the other elements within the same class) jQuery - 仅针对单击元素进行更改,而不是所有具有相同类的更改 - jQuery - change for only clicked element, not all with the same class 标签更改仅适用于单击的元素,而不是所有具有相同类的元素 - tab change for only clicked element, not all with the same class Jquery - 我只想为单击按钮的元素切换 class。 目前它为所有具有相同 class 的元素切换 - Jquery - I want to only toggle class for the element whose button is click. Currently it toggles for all elements with same class 仅将 ngClass 用于一个元素,而不是所有具有相同 class 的元素 - Using ngClass for only one element and not all elements with the same class 针对所有班级,仅选择单击的元素 - Targeting all of class, select only clicked element 单击将class添加到具有特定类的元素,并将其从具有相同类的所有其他元素中删除 - On click add class to element with certain class and remove it from all other elements with same class 将函数应用于所有具有相同类的元素 - apply function on all elements with same class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM