I need a jQuery function that filters a set of data-attributes .
In my HTML structure, I have several list items, and there are attributes there:
data-offer and data-subcat these two will be used to filter items using multiple input flags.
So far, I have this jQuery that does the filtering, but not the way I want.
$(".cs-widget-content").on("change", "input[type=checkbox]", function () { $(".five-column > li.column").hide(); $(".cs-widget-content").find("input:checked").each(function (i, el) { $(".five-column > li.column").filter('[data-offer="' + el.id + '"]').show(); }); $(".cs-widget-content").find("input:checked").each(function (j, el) { $(".five-column > li.column").filter('[data-subcat="' + el.id + '"]').show(); }); });
Here is jsfiddle
Solution I want:
All data must be loaded on the page load (which works).
The input filter for both data attributes should work together (for example, when the input is checked for data-offer , it will show that the data and if the data-subcat is checked, it will display data for this attribute as well as in the previous data-offer check.
If any input is not verified, the data should be visible back.
I look forward to your help.
thanks
source share