How to prevent keyup function from lagging when the user types

I am trying to create a search function in jQuery:

$('input').on('keyup', function(){
    var searchTerm = $("input").val().toLowerCase();
        if ($(this).filter('[data-text *= ' + searchTerm + ']').length > 0 || searchTerm.length < 1) {
        } else {

Each time the user types in the input, it gets compared to the data attribute value of .item divs. If the data attribute of that element contains the search query, it gets displayed – otherwise hidden.

This works perfectly in Chrome, however it is really laggy in Safari for some reason when the user is typing.

Is there a way to fix this?

There are about 1400 divs (.item), and the data-text attribute is only around 10-20 characters for each element

Edit, fixed by removing .show() and .hide() – and replacing with native Javascript

49 thoughts on “How to prevent keyup function from lagging when the user types”

  1. therapie de couple uccle pharmacie besse annecy , therapie viceland streaming pharmacie annecy geneve , DГіnde comprar Suhagra 50 mg, DГіnde comprar Suhagra 50 mg. Comprar Suhagra sin receta Comprar Suhagra genГ©rico [url=]Suhagra en farmacia Chile[/url] therapie de couple jean reno Forcan venta online, Comprar Forcan medicamento. Forcan en farmacia Ecuador Comprar Forcan genГ©rico [url=]Comprar Forcan medicamento[/url] , traitement kyste ovarien pharmacie ouverte vannes , therapie de couple clermont ferrand. pharmacie rue bailly Silagra en farmacia Miami, DГіnde comprar Silagra 100. Comprar Silagra sin receta Comprar Silagra genГ©rico [url=]Silagra en farmacia Miami, Comprar Silagra medicamento[/url] , medicaments wellbutrin pharmacie bordeaux palais de justice, pharmacie monge therapie cognitivo-comportementale adolescent . act therapy wiki, pharmacie bailly site internet pharmacie bailly gare st lazare pharmacie a proximite de garde .


Leave a Comment