Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9153931
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:21:08+00:00 2026-06-17T12:21:08+00:00

I seem to have a timing problem with my jQuery change and click events.

  • 0

I seem to have a timing problem with my jQuery change and click events. In my site I have it with an Ajax post instead of an alert, but it’s easier to reproduce it using the alert. I have a simple HTML page using jQuery Version 1.7.1.

The scenario is editing the textbox and then directly clicking the button. The change event is always fired but if it contains a alert the click event is never called. If I cheat and put a timeout around the alert (you might have to play around a bit with the values there) the click event is called normally.

/** EDIT **/
If you set a breakpoint somewhere in the change event and wait for a few seconds the click event will aslo fail to fire.

<script type="text/javascript">
$(document).ready(function ()
{
    $("input[type=text]").change(function () {
        //alert('changed');

        $("#text").text('changed');

        setTimeout(function () {
            $("#text").text('changed timeout');
            alert('changed');
        }, 100);

    });

    $("input[type=submit]").click(function () {
        alert('clicked');
        $("#text").text('clicked');
    });
});
  </script>
  <div id="main">
    <div class="container">
        <input type="text" />
        <input type="submit" value="click me" />
        <div id="text" >bla</div>
    </div>
  </div>

My Ajax call that has the save behavoir is the following:

$.ajax({
        type: 'POST',
        url: postUrl,
        data: form.serialize(),
        beforeSend: function () {
            // display overlay for work in progress
        },
        success: function (result) {
            updateTableSuccess();
        },
        complete: function () {
            // hide overlay for work in progress
        },
        error: function (jqXHR) {
            if (jqXHR.responseText.length > 0) {
                showErrorMessage(jqXHR.responseText);
            }
        }
    });

The overlay is simply appending 2 divs to the body Tag.

/** Edit **/ It seems that the overlay is the real problem and causes the same behavoir as the alert and stops the click event from being fired.

showWorkInProgress = function (message, elementId)
{
    if ($("#overlay").length == 0)
    {
        $("<div id='overlay' class='ui-widget-overlay'></div>").appendTo("body");
    }

    if ($("#workInProgress").length == 0)
    {
        $("<div id='workInProgress'></div>").appendTo("body");
    }

    $("#workInProgress").html(message);
    if (elementId != null)
    {
        $("#workInProgress").center(elementId);
    }
    else
    {
        $("#workInProgress").center();
    }
    $("#overlay").show();
    $("#workInProgress").show();
};

Can anyone explain why jQuery behaves like this and how I could do this nicer without the setTimeout hack?

Thanks for any help =)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T12:21:09+00:00Added an answer on June 17, 2026 at 12:21 pm

    Just for a short answer if anyone else has the same problem: The problem really is the overlay which is blocking the whole page, which causes the same behavoir as the alert.

    My explanation for it is that the change event gets fired, blocks the UI and the click event can’t be fired anymore because of that as suggested by https://stackoverflow.com/users/1861269/john-gerdsen.

    The only solution I found for this problem was to make the overlay smaller and block only the part that really needs to be blocked. The timeout worked aswell but not in every case because every machine had different performance.

    This might help anyone trying which is also fighting with the overlay problem:
    HTML "overlay" which allows clicks to fall through to elements behind it

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I seem to have a problem passing some strings on from one form to
I seem to have found a bug in jQuery UI that duplicates dragged elements
I seem to have a problem with getting MVC to fill in my custom
I seem to have the exact opposite problem than this question on stopping dock
I have seem many forum posts / responses on this subject but I am
I seem to have problem getting linked servers working to query between database/servers running
I have an interesting (but frustraring) problem. I have an application which uses the
I have been looking around for some time now, but can't seem to find
I seem to have hit a snag while building my project using Ant. The
i seem to have some trouble installing autopy.h https://github.com/msanders/autopy/#introduction i already tried the installation

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.