JQuery instant addClass or hide class

934 views Asked by At

When adding JQuery to hide a class it of course waits for the page to load then hides the class, same thing for 'addClass'. There has got to be a better or faster way for it to 'load' as the page is loading. Anyone know of any ideas? I have given my sites JQuery scripts below with links to see them in action:

Hides sub filters: Link to example of my script to hide sub filters (notice left navigation filters)

if(jQuery('.refinement_category_section').length){
   jQuery('.refinement_custom_category_section').hide() &&
      jQuery('.refinement_filter').hide();
}

jQuery(document).ready(function(){                         
   if(jQuery('.refinement_category_section').length){
      jQuery('.refinement_custom_category_section').hide() &&
         jQuery('.refinement_filter').hide();
   }
});

OR

Adds a Class:Link to example of my script adding Class (notice left navigation filters)

$('.refinement_brand_section').parent().addClass('filterresults');

2

There are 2 answers

1
tvanfosson On BEST ANSWER

Using Firebug, it appears that the issue is with the number of images that you are loading. My suggestion is to dynamically load pictures for your items using javascript after applying your style changes or have a smaller number of items on the page (or both). This will result in a degraded, but still functional interface for non-javascript users. For javascript-enabled browsers, you can adjust how and how many images are loaded to still achieve a nice effect.

You should also use sprites for your small interface elements so that you're downloading a single image and using CSS to display various portions of it. Combining your javascript files and stylesheets for your production site would also help quite a bit -- you've got 20+ js files and 13+ stylesheets, each of which requires a separate request. You might want to run YSlow and follow it's other recommendations.

3
yoavmatchulsky On

you can add CSS rules to hide these classes and then change it after jquery loads

.refinement_category_section, .refinement_custom_category_section, .refinement_filter {
  display: none;
}