EDIT: The question morphed into how to optimize a massive CSS change to 700 or more divs. I'm leaving the old question below to describe my original approach.
I have the following jQuery but it is not behaving as I expect. There are around 700 divs with class gr so hiding them takes a noticeable time. I am trying to do:
- When "Show/hide Pronunciation" is clicked, immediately change that text to "Working"
- Wait until all 'div.gr' are hidden/shown
"Working" goes back to "Show/hide Pronunciation"
$(document).ready(function () { $('#togglePron').click(function() { $('#togglePron').html("Working..."); $('div.gr').toggle(); $('#togglePron').html("Show/hide Pronunciation"); }); }); ... ... <div class="pronlink" id="togglePron">Show/hide P</div> <div class="gr">hai</div><div class="zi">A</div> <div class="gr">nao</div><div class="zi">B</div> etc.
Thanks to Mike Lentini there's a jsfiddle for this question.
This is the full page I'm working on
The behavior I observe is that "Show/hide P" takes a noticeable time to change, then it changes briefly to "Working", and it goes back to "Show/hide". So is jQuery bunching together both the html() and .toggle(), instead of running html() first?
This seems to be browser specific because in Opera it does what I want. In IE 7 and Chrome 18, the behavior is as I described. Is there a way to make the behavior I want in Chrome happen? Or a better way to do what I am describing?