Reputation: 97
I'm trying to filter out some children elements, but I'm not managing to iterate throught children properly. Whats wrong in my code:
$("#filter").on("click", function() {
$("div#results > div").each(function () {
if(!$(this).attr('subcategory', 0)){
$(this).remove();
}
});
});
Upvotes: 0
Views: 1258
Reputation: 74748
Why go for .each()
loop go for attribute-not-equal-selector:
$("#filter").on("click", function() {
$('div#results > div[subcategory!="0"]').remove();
});
Upvotes: 0
Reputation: 388446
Use attribute not equals selector
$("div#results > div[subcategory!=0]").remove()
Upvotes: 3
Reputation: 82251
$(this).attr('subcategory', 0)
will set the value to attribute. try this:
$("#filter").on("click", function() {
$("div#results > div").each(function () {
if($(this).attr('subcategory')==="0")){
$(this).remove();
}
});});
Upvotes: 1