I am working with a server that responds with an HTML response of the form:
<div>
<table>
<thead>
<tr>
<th>Name</th>
<th>Country</th>
</tr>
</thead>
<tbody>
<tr>
<td>John Doe</td>
<td>USA</td>
</tr>
<tr>
<td>James Doe</td>
<td>Canada</td>
</tr>
<tr>
<td>Jonas Doe</td>
<td>UK</td>
</tr>
</tbody>
</table>
</div>
My problem is that, before I insert this table, I want to filter the rows. For example, let's say I wanted to only have the rows with USA as the value in the second cell.
How could I do this?
Here's my current status in trying to solve this problem.
https://jsfiddle.net/bmp6a4gh/
In essence, Im trying to create a function that accepts the html string and injects a string (of the same format) but with the filtered rows.
function processResponse(html){
var $html = $(html);
//perform filtering here
//I only want elements from USA
$html.filter(function(index, element){
return true;
});
$("#response").html($html);
}