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 3309408
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:38:14+00:00 2026-05-17T21:38:14+00:00

This runs fast compared to other’s.But i dont know how fast it would be

  • 0

This runs fast compared to other’s.But i dont know how fast it would be at slow computers..
The code filters the results dymanically. The criteria are set in css class..

$(document).ready(function ()
{


    $("#filters a").click(function(event)
    {
        event.preventDefault();
        event.stopPropagation();
        if($(this).hasClass("checked"))
        {
            $(this).removeClass("checked");
        }
        else if(!$(this).hasClass("disabled"))
        {
            $(this).addClass("checked");
        }
        else
            {
                return false;
            }


        var results=$("#products li");
        results.hide();
        $("#filters li.filtersGroup a").removeClass("disabled");
        $("#filters li.filtersGroup").each(function(index) {
            var classes="";

            $(this).find("a.checked").each(function(index) {
                classes=classes+ "." + $(this).attr("id") +",";
            });
            if(classes=="") return true;

            results=results.filter(classes.substr(0,classes.length-1));
//periorismos
                $("#filters li.filtersGroup").not($(this)).each(function (index){
                    $(this).find("a").each(function(index) {


                if(results.filter("." + $(this).attr("id")).length<=0) {
                       $(this).removeClass("checked").addClass("disabled");
                   }

            });



        });
    });
    results.show();



})
});

Any ideas how to improve it? Also what can i do about preventdefault (itsnot triggered if the whole document isnt loaded,because this may be a problem for impacient people..

  • 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-17T21:38:15+00:00Added an answer on May 17, 2026 at 9:38 pm

    One thing I notice is you’re doing a lot of unnecessary calls to $():

        if($(this).hasClass("checked"))
        {
            $(this).removeClass("checked");
        }
        else if(!$(this).hasClass("disabled"))
        {
            $(this).addClass("checked");
        }
        else
        {
            return false;
        }
    

    Every time you do $(this), there are multiple underlying function calls and a couple of memory allocations involved. It’s completely unnecssary. Just do:

    var $this = $(this);
    

    …at the beginning, and then:

        if($this.hasClass("checked"))
        {
            $this.removeClass("checked");
        }
        else if(!$this.hasClass("disabled"))
        {
            $this.addClass("checked");
        }
        else
        {
            return false;
        }
    

    This (no pun) applies to any time you call $(), not just $(this), but you need to be sure you only cache the result for as long as it really will be unchanged (as that varies depending on the selector or element you’re passing in). Without reading through with a fine-toothed comb, for instance, you can probably cache the result of $("#filters li.filtersGroup") in at least one place rather than making jQuery do the whole thing over again.

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

Sidebar

Related Questions

This code runs on my local RoR/Windows 7 (64-bit): sql = ActiveRecord::Base.connection() last_pk =
I have a python script the runs this code: strpath = sudo svnadmin create
I have some C++ source code with templates maybe like this - doxygen runs
This piece of code is very slow. Execution from the slime-repl on my netbook
My calculations are something like this: f[x_]:= (*runs fast*) g[x_]:=(*runs fast*) h[x_]=depends on f[x],g[x]
I've struggled with this one for a long time. This query runs fairly fast
I have a program which does a system call: latex somefile.latex This runs ok,
When this one runs everything goes fine: (r^newobject$, views.myobjects.newobject), All the CSS + JS
This is pretty interesting, this site runs a speed test and compares all of
I have a method which runs this: Track* track = [[Track alloc] init:[obj objectForKey:@PersistentID]

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.