Background
I have approximately 1000 elements, some of which I need to toggle between visible and not visible, trigger by a checkbox changing.
I've read through the different approaches to doing this (.hide()/.show(), .toggle(), .addClass('hidden'), .css('display','block'), etc). I've tried them all. The class changing seems to be the best, but even with this method, after a tap, there is lag for about a second with nothing appearing to happen. When the checkbox and elements change.
Code
I have a list of products, some retired and some active. The retired products have class of .retired, and the active have a class of .active.
Additionally, every active row has a class of .hidden. This class simply has the style of display:none.
HTML:
<li id="1" class="hidden active"></li>
<li id="2" class="hidden active"></li>
<li id="3" class="retired"></li>
<li id="4" class="hidden active"></li>
CSS:
.hidden {
    display:none;
}
My jQuery is currently:
$('#show-only-retired').change(function(event){
    if ( $(this).prop('checked') ) {
        $('li.active').addClass('hidden');
    } else {
        $('li.active').removeClass('hidden');
    }
});
Goal
I'd like to have the checkbox immediately change on tap, and a loading icon appear beside it, with the loading icon disappearing after the change changeover is complete. I can't find a way to tap into the beginning and end of the process of toggling the class.
Question
Is it possible?
 
     
    