I am trying to learn jQuery and JS. I want to filter the table to be the values in my arrays. The month will always be one month but the Name may have more that one name.
The results I want is:
| Office | Name | Month | Quantity |
|---|---|---|---|
| 1a | Abe D | Feb | 13 |
| 1a | Jon R | Feb | 12 |
$(document).ready(function(){
var names = ["Abe D", "Jon R"];
var mth = "Feb"
$("button").click(function(){
$("td:nth-child(2)").each(function(){
let tr = $(this);
let mths = tr.find('td:nth-child(3)').text();
console.log(mth + ' : ' + mths)
if(names.indexOf($(this).text()) == -1 || mths !== mth){
$(this).parent().hide();
}
});
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<thead>
<tr>
<th>Office</th>
<th>Name</th>
<th>Month</th>
<th>Quantity</th>
</tr>
</thead>
<tr>
<td>1a</td>
<td>Abe D</td>
<td>Jan</td>
<td>10</td>
</tr>
<tr>
<td>1a</td>
<td>Abe D</td>
<td>Feb</td>
<td>13</td>
</tr>
<tr>
<td>1a</td>
<td>Jon R</td>
<td>Jan</td>
<td>9</td>
</tr>
<tr>
<td>1a</td>
<td>Jon R</td>
<td>Feb</td>
<td>12</td>
</tr>
<tr>
<td>2b</td>
<td>Eve C</td>
<td>Jan</td>
<td>13</td>
</tr>
<tr>
<td>2b</td>
<td>Eve C</td>
<td>Feb</td>
<td>14</td>
</tr>
</table>
<button>Filter</button>
How do I get the filter working?