[Need Help] jQuery Event binding and object cache issues.

Hi Guys,
My recent submission (HTML5/Bootstrap Template) got soft rejected. The reviwer mentioned two issues - 1. PROPER EVENT BINDING and 2. CACHE JQUERY OBJECTS. I have tried to find and fix them by following resources and updated the JS file which I am using to control jQuery plugins. Can anyone please help me by checking it? I want to be sure before the resubmission.
Here is the updated file: https://www.dropbox.com/s/70j7c2zfbju7qv5/main.js?dl=0

Thanks in advance :slight_smile:

Hi,

Here some examples about what you should fix:
1- Event binding
$(’.list,switchToGrid’).click(function(e) // Do not use this way

$(’.list,switchToGrid’).on(‘click’, function(e) // Use like this

2- Cache jQuery Objects
// Don’t use like this.
$(’.item-list’).addClass(“make-list”);
$(’.item-list’).removeClass(“make-grid”);
$(’.item-list’).removeClass(“make-compact”);

Use like this:
var itemList = $(’.item-list’);
itemList.addClass(“make-list”);
…

Good luck.

1 Like

Hi @eony,

Thank you so much for your detailed instructions. I have updated main.js according to your recommandation :slight_smile: It will be really helpful if you can check updated version from here: https://www.dropbox.com/s/ktv65h34m9kzpmh/main-updated.js?dl=0

Have nice day

Hi,

No problem.
Almost there. You don’t need to declare itemList twice. Just move it top of the code and you can declare variables for $(’.grid’), $(’.list’) too. If you will use jquery object more than 2, just create a variable and use it like that.

Regards.

1 Like

Hi @eony, Just made the changes :slight_smile:

Now, it seems OK :smiley: Please, let me know your opinion.

Thanks for your co-operation

Yes, it is okay. You can tidy the code a little but it is up to you.

Good luck.

Yes, will do that :slight_smile: and Thanks a lot for your help