javascript - jQuery show rows that meet criteria -
i have page multiple tabs on per region.
on page load, load of data hidden table , when click on tab, pulls in table , filters data (removes rows not needed tab).
for example, each tr
in table has classes on region names.
<tr class="americas emea apac"></tr>
<- row falls 3 regions.
i have tab example shows me data americas:
$('#' + tab).find("#trainingevents .results tr:not(.americas)").remove();
removes rows table not have americas
in class.
my goal make condition 3 of them required.
when click "global", row must contain 3 of classes or removed table.
what best approach accomplish this? thinking contains
true
if 1 of them met.
i think can use .filter() accomplish want:
function filtertable(selector) { $("table tr").hide().filter(selector).show(); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <table> <tr class="americas emea apac"> <td>americas emea apac</td> </tr> <tr class="americas"> <td>americas</td> </tr> <tr class="americas emea"> <td>americas emea</td> </tr> <tr class="apac"> <td>apac</td> </tr> </table> <input type="button" value="americas" onclick="filtertable('.americas');" /> <input type="button" value="emea" onclick="filtertable('.emea');" /> <input type="button" value="apac" onclick="filtertable('.apac');" /> <input type="button" value="global" onclick="filtertable('.americas.emea.apac');" />
Comments
Post a Comment