[英]Multiple elements with the same class, get the text of only the clicked element
[英]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.