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

  • SEARCH
  • Home
  • 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 6641007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:45:36+00:00 2026-05-25T23:45:36+00:00

I have used firebug and IE profilers and can see what function in my

  • 0

I have used firebug and IE profilers and can see what function in my code is causing the slowness. Being new to jquery, the recommendations that I have read online are not clear to me. I have made an example page that shows the slow behavior when you check or uncheck a check box. No surprise that this is fast using Chrome.

The function that is slow can be found on line 139.

$('.filters input').click( function() 

JSFiddle can be found here

The code is 122 KB and can be found here

UPDATE: if you know of any examples online that are similar in function and faster, please share.

  • 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-25T23:45:37+00:00Added an answer on May 25, 2026 at 11:45 pm

    i had a brief look through your code, but it was very hard to follow. it seemed as if you were looping through things many many times. i used a much simpler approach to get the list of all states.

    your approach was
    * make a massive string which contained every class (possibly repeated multiple times)
    * chop it up into an array
    * loop through the array and remove duplicates

    i simply took advantage of the fact that when you select something in jQuery you get a set rather than a single item. you can therefore apply changes to groups of object

    $(document).ready(function () {
        //this will hold all our states
        var allStates = [];
    
        //cache filterable items for future use
        var $itemsToFilter = $(".filterThis");
    
        //loop through all items. children() is fast because it searches ONLY immediate children
        $itemsToFilter.children("li").each(function() {
    
            //use plain ol' JS, no need for jQuery to get attribute
            var cssClass = this.getAttribute("class");
    
            //if we haven't already added the class
            //then add to the array
            if(!allStates[cssClass]) {
                 allStates[cssClass] = true;
            }
        });
    
        //create the container for our filter
        $('<ul class="filters"><\/ul>').insertBefore('.filterThis');
    
        //cache the filter container for use in the loop
        //otherwise we have to select it every time!
        var $filters = $(".filters");
    
        // then build the filter checkboxes based on all the class names
        for(var key in allStates) {
            //make sure it's a key we added
            if(allStates.hasOwnProperty(key)) {
                //add our filter
                $filters.append('<li><input class="dynamicFilterInput" type="checkbox" checked="checked" value="'+key+'" id="filterID'+key+'" /><label for="filterID'+key+'">'+key+'<\/label><\/li>');
            }
        }
    
        // now lets give those filters something to do
        $filters.find('input').click( function() {
            //cache the current checkbox
            var $this = $(this);
    
            //select our items to filter
            var $targets = $itemsToFilter.children("li." + $this.val());
    
            //if the filter is checked, show them all items, otherwise hide
            $this.is(":checked") ? $targets.show() : $targets.hide();
    
        });
    });
    

    FIDDLE: http://jsfiddle.net/bSr2X/6/

    hope that’s helpful 🙂

    i noticed it ran quite a bit slower if you tried to slideup all the targets, this is because so many items are being animated at once. you may as well just hide them, since people will only see the ones at the top of the list slide in and out of view, so it’s a waste of processor time 🙂

    EDIT: i didn’t add logic for show all, but that should be quite a trivial addition for you to make if you follow how i’ve done it above

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

Sidebar

Related Questions

Update 2 : So I never have used the debug function in firebug, but
I am trying to test an API via AJAX. I have used JQuery: $(document).ready(function(){
I have used traditional version control systems to maintain source code repositories on past
I have used IPC in Win32 code a while ago - critical sections, events,
I have the following code in my application: $(.deleteproduct).click(function() { id = this.id; alert(id:
I have a beginner level Json question with MVC.net (I've never really used jquery
I currently have a JS function that allows me to load partial content from
I have a website running a basic ASP.NET application that is mostly used from
I have used this datepicker for quite awhile in this specific code. I made
I have used jquery tabs for loading data with ajax, but I need to

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.