javascript - Show/Hide tr elements based on multiple CSS classes and input from multiple checkboxes -
i have large html page contains variety of tables. create set of checkboxes @ top of page can used filter values in various tables. value in table
can belong multiple groups, group indicated unique css class. here tricky part, when group selected, values tagged corresponding css class must shown. e.g. if group selected values tagged class should displayed.
the following code snippet representing display structure:
<input type="checkbox" name="a" value="a"> <input type="checkbox" name="b" value="b"> <tr id="abc" class="stylingclass a"> <tr id="def" class="stylingclass b"> <tr id="ghj" class="stylingclass b">
i understand how hide 1 <tr>
element or based on checkbox, i'm not sure how element #ghj
displayed when selected or b selected. scalable n groups. know tall order quite stuck.
try
jquery(function ($) { var $ins = $('input[type="checkbox"]'), $trs = $('tr.stylingclass'); //change handler checkboxes $ins.change(function () { //get value of checked checkboxes var vals = $ins.filter(':checked').map(function () { return this.value; }).get(); //hide trs $trs.hide(); //if there @ least 1 checked item if (vals.length) { //show trs 1 of selected value class $trs.filter('.' + vals.join(', .')).show(); } }) })
demo: fiddle
Comments
Post a Comment