<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<div class="x-field">
<input type="text" id="search" placeholder="Type to search">
<span class="close">×</span>
</div>
<table id="table">
<tr>
<td>Apple</td>
<td>Green</td>
</tr>
<tr>
<td>Grapes</td>
<td>Green</td>
</tr>
<tr>
<td>Orange</td>
<td>Orange</td>
</tr>
</table>
<style>
body {padding: 20px;}
input {margin-bottom: 5px; padding: 2px 3px; width: 209px;}
td {padding: 4px; border: 1px #CCC solid; width: 100px;}
.x-field{
display:inline;
position:relative;
}
.x-field .close {
position:absolute;
padding:0 5px;
right:0;
cursor: pointer;
display: none;
}
</style>
<script>
var $rows = $('#table tr');
$('#search').keyup(search);
$('.close').click(function(){
$('#search').val('');
$rows.show();
$('.close')[0].style.display = 'none';
});
function search() {
if($('#search').val()){
$('.close')[0].style.display = 'inline';
}else{
$('.close')[0].style.display = 'none';
}
var val = $.trim($(this).val()).replace(/ +/g, ' ').toLowerCase();
$rows.show().filter(function() {
var text = $(this).text().replace(/\s+/g, ' ').toLowerCase();
return !~text.indexOf(val);
}).hide();
}
</script>