I have a set of checkboxes and select list that are being used to filter elements.
Here is my html:
<div id="users">
<input name="user" type="checkbox" value="1">
John
<input name="user" type="checkbox" value="2">
Mike
<input name="user" type="checkbox" value="3">
Peter </div>
<select name="products">
<option value="4">Product 1</option>
<option value="5">Product 2</option>
<option value="6">Product 3</option>
</select>
<ul id="items">
<li data-filter="1">Item 1</li>
<li data-filter="2">Item 2</li>
<li data-filter="1">Item 3</li>
<li data-filter="3">Item 4</li>
</ul>
and here is javascript:
$('select[name=products]').change(function() {
var filter = $(this).val();
filterList(filter);
});
//News filter function
function filterList(value) {
var list = $("#items li");
$(list).fadeOut("fast");
if (value == "all") {
$("#items").find("li").each(function () {
$(this).delay(200).slideDown("fast");
});
} else {
$("#items").find("li[data-filter*=" + value + "]").each(function () {
$(this).delay(200).slideDown("fast");
});
}
}
My problem is now to include checkboxes as well as part of filtering options, but I'm not sure which way to go. Do I coma separate data-filter values like: data-filter="1,3" where 1 is product, and 3 is user, or add new data attribute entirely?
