jQuery delay does not seem to give the correct delay for this kind of event
<p>I had some help today with a need and this is what I have come up with:</p>

<pre><code>      $(window).keypress(function (e)
      {
          if (e.keyCode == 13)
          {
              $('#doCheck')
        .css('color', '#666')
        .delay(100)
        .queue(function (next)
        {
            $(this).css('color', '#00ff00');
            next();
        });

        doCheck('mark1');
      }

&lt;input id='doCheck' type="button" onclick="doCheck('mark1'); return false;" value="Mark" /&gt;
</code></pre>

<p>The idea here is that when a user presses the ENTER key then the color of the button will change color for 100 milliseconds and at the same time I call a function called doCheck that will call AJAX.</p>

<p>My problem is that there seems to be some minimal delay of almost a second before the color of the button changes back to #666. I expect a much shorter time but even if I set the delay to 10 then it still seems to delay for 1/2 to one second. I should add that if I set a long delay like five seconds then it really does do the five seconds.</p>

<p>I can't see what's wrong here. </p>

<p>Does anyone have any ideas? </p>

<p>thanks,</p>

<p>Here is the doCheck function. The function works correctly. Just the button thing is giving me problems. Note that I just changed it to async: true   </p>

<pre><code>function doCheck(task)
      {
          var parms = {
              task: task,
              pk: $('#Q_PartitionKey').val(),
              rk: $('#Q_RowKey').val(),
          };
          $.ajax({
              type: "POST",
              traditional: true,
              url: '/power/check',
              async: true,
              data: parms,
              dataType: "json",
              success: function (data)
              {
                  // $('#doCheckMark').attr("disabled", false);
                  // $('#doCheckMark').css("color", "#000");
              },
              error: function ()
              {
                  var cdefg = data;
              }
          });
      }
</code></pre>
