ここで私はフィドルを作成し.addClass
ました。クリックされたデータIDがデータカテゴリと等しい場所を考えることはできません。フィドルを見てください。もっとよく理解できます。
ここでは.addClass
、すべての.item
クラスについて説明しますが、data-id に一致するデータ カテゴリにクラスを追加するように記述する方法がわかりません。
未完成の jQuery スニペット:
$(".breadcrumb-cell .breadcrumb").click(function () {
var theID = $(this).data("id"),
theCAT = $('.item').attr("data-category"),
item = $('.item')
//This just shows you that when you click the element it returns the data-id each click
alert(theID);
// Here I gave it a few shots but no success, so I just add .active to all
item.addClass('active');
});
これはちょっとばかげているように感じますが、私はこの種の書き込み (データ属性の一致) をいじっていないので、知識の少しの隆起は途方もないでしょう.
回答: by: スシャント --
$(".breadcrumb-cell .breadcrumb").click(function () {
var theID = $(this).data("id"),
$allItem = $('.item'),
$currItem = $('.item[data-category=' + theID + ']')
$currItem.addClass('active');
$allItem.not($currItem).removeClass('active');
});