Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Keyup contains filtering to block results

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?

like image 945
Dmitry B. Avatar asked Jan 24 '26 19:01

Dmitry B.


1 Answers

You need to clone the results:

var results = $('#icons section > .fontawesome-icon-list > .fa-hover:Contains("' + filter + '")').clone();
like image 164
PrinceG Avatar answered Jan 26 '26 10:01

PrinceG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!