Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6240493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T11:34:48+00:00 2026-05-24T11:34:48+00:00

I wrote the following script for a page which has been loaded with a

  • 0

I wrote the following script for a page which has been loaded with a data set of about 1000 items (all in one server call–no AJAX). On each keyup the script converts the text input into a CSS-standards-friendly string (removes spaces, downcases, etc.), then matches that string with CSS classes that I’ve loaded each item with, and adjusts the “hide” or “show” accordingly for that element.

$(document).ready(function(){
    $('ul.players li').hide();      
    $("#filter-input").keyup(function () {
        var lowercase = $(this).val().toLowerCase();
        var spaced = lowercase.replace(/[ _]/, '-');
        var outputString = spaced.replace(/[^a-z-]/i, '');
        $('ul.players li').hide();      
        $('ul.players li[class*="'+outputString+'"]').show();
    });
});

Example of HTML this is working on:

<form>
    <input id="filter-input" type="text" />
</form>
<ul class="players">
    <li class="firstname lastname teamname position cityname">
        <div>Basic player info here...</div>
    </li>
</ul

The script is working just fine (in the simple capacity that I need it to work)–but it’s very laggy. What can I do to optimize this for performance?

(Obviously, there are a lot of class switches across those many elements–I don’t think I can avoid that–but maybe there’s something to be done about the string conversions)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T11:34:49+00:00Added an answer on May 24, 2026 at 11:34 am

    You can try to insert a <style> element in the head that matches them – this will be a lot quicker.

     $('head').append('<style id="player-style"></style>');
    

    When a key is pressed – edit this style:

     $('#player-style').html('.' + outputString + ' { display: block }');
    

    Note that you might have to use .text() to replace the contents – haven’t tried it.

    Just to mention that you will need some more CSS to hide all ul.players li and show only the needed with the trick above. I think this will be fast enough, since the browser will be doing the showing and hiding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

hi i have the following page: [here][link removed] the script i wrote is working
I wrote the following Nant script on my Vista dev machine and was pleased
I have an interesting problem. I wrote the following perl script to recursively loop
I have a GridView which has following template field that holds the filename, when
I'm trying to extract data from the following page: http://www.bmreports.com/servlet/com.logica.neta.bwp_PanBMDataServlet?param1=&param2=&param3=&param4=&param5=2009-04-22&param6=37# Which, conveniently and inefficiently
I have been trying to make a page which combines web.py and JavaScript, and
The following script returns 20 instead of 21! var d = new Date(2010/03/21); document.write(d.getDate());
Javascript can manipulate the document the browser is displaying, so the following: <script> document.write(<table><tr><td>Hola</td><td>Adios</td></tr></table>);
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.