[英]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.