Hi,

I used toggleClass method to toggle the colors of my message when the
user clicks a button. toggleClass() worked well if I didn't specify
any duration i.e. instanteous switch from white background to red
background. The problem arises when I added a duration of ,say, 2s. If
the user clicked the button before the message has reached the final
state (say the user clicked the button 1s after the 1st click),
clicking the button will not revert the message to its original state
i.e. white background. How do I fix this?

Also, the reason as why I use _class_ is I want to define the UI
properties in CSS instead of in JS as keys/values.

Thanks

<script type="text/javascript">
  $("#clickMe").click(function() {
            $("#console").toggleClass('red', 2000);
            return false;
        });
 </script>

<style>
.red {background-color:red;}
</style>

<body>
<div id="console">Empty</div>
<div id="clickMe">Click Me</div>
</body>

Reply via email to