how can function revert showing when filters removed?
i've tried changing if (attrcolor == 'all') {...}
if (attrcolor == 'all' || attrcolor == '') {...}
i've posted fiddle simple example of function here: http://jsfiddle.net/chayacooper/wzpmh/88/
$(document).ready(function () { var selected = []; $('#attributes-colors *').click(function () { var attrcolor = $(this).data('color'); var $this = $(this); if ($this.parent().hasclass("active")) { $this.parent().removeclass("active"); selected.splice(selected.indexof(attrcolor),1); } else { $this.parent().addclass("active"); selected.push(attrcolor); } if (attrcolor == 'all') { $('#content').find('*').show(); } else { $("#content").find("*").hide(); $.each(selected, function(index,item) { $('#content').find('[data-color *="' + item + '"]').show(); }); } return false; }); });
see this: demo
if (attrcolor == 'all' || !selected.length) { $('#content').find('*').show(); } else { $("#content").find("*").hide(); $.each(selected, function (index, item) { $('#content').find('[data-color *="' + item + '"]').show(); }); }
edit:
update per @arunpjohny's suggestion:
using .children() selector better * selector child li
s
if (attrcolor == 'all' || !selected.length) { $('#content').children().show(); } else { $("#content").children().hide(); $.each(selected, function (index, item) { $('#content').find('[data-color *="' + item + '"]').show(); }); }
Comments
Post a Comment