Reputation: 426
I have an html document with the field to filter text in blocks. Here is my code:
JS:
$('#search-input').on('keyup', function() {
var filter = $(this).val();
var results = $('#icons section > .fontawesome-icon-list > .fa-hover:Contains("' + filter + '")');
console.log(results);
$('#results .row').html(results);
$('#results').show();
});
The filtered data is output in block #results .row.
The script works correctly only the first time (the first event 'keyup'). How to make so that at every event 'keyup' it filter the data correctly?
Upvotes: 3
Views: 62
Reputation: 982
You need to clone the results:
var results = $('#icons section > .fontawesome-icon-list > .fa-hover:Contains("' + filter + '")').clone();
Upvotes: 1