Reputation: 1779
When filter button is clicked I would like it to hide all the li where the data attribute hasrelated=0
html
<li data-mostsaved="0" data-hasrelated="0" data-mostplayed="2">img</li>
JQ
$( ".has-related" ).click(function() {
if ($("li").data('hasrelated') == '0') {
$("li").hide();
}
});
Upvotes: 0
Views: 1022
Reputation: 1154
I've written this using $.each
function by jQuery:
$("a_button").click(function(){
$("li").each(function(){
var a = $(this).data("hasrelated");
if(a == 0){
$(this).toggle();
}
});
});
Upvotes: 0
Reputation: 4339
You can use the Attribute Equals Selector [name="value"] to check where the data attribute hasrelated=0, as in:
$('li[data-hasrelated=0]').hide();
Upvotes: 0
Reputation: 986
Try this:
$(".has-related").click(function() {
$('li').each(function() {
if ($(this).data('hasrelated') == '0') {
$(this).hide();
}
});
});
Upvotes: 4