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 8815361
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:21:28+00:00 2026-06-14T04:21:28+00:00

I am using the jQuery trigger method to call an event… but it behaves

  • 0

I am using the jQuery trigger method to call an event… but it behaves inconsistently. Sometimes it call the event, sometimes it does not.

<a href="#" onclick="
    $(this).trigger('custom-event');
    window.location.href = 'url';
    return false;
">text</a>

The custom-event has lots of listeners added to it.
It is as if the trigger method is not synchronous, allowing the window.location.href be changed before executing the events. And when window.location.href is changed a navigation occurs, interrupting everything.

How can I trigger events synchronously?

Using jQuery 1.8.1.

EDIT

I have found that the event, when called has a stack trace like this:

  1. jQuery.fx.tick (jquery-1.8.1.js:9021)
  2. tick (jquery-1.8.1.js:8499)
  3. jQuery.Callbacks.self.fireWith (jquery-1.8.1.js:1082)
  4. jQuery.Callbacks.fire (jquery-1.8.1.js:974)
  5. jQuery.speed.opt.complete (jquery-1.8.1.js:8991)
  6. $.customEvent (myfile.js:28)

This proves that jQuery trigger method is asynchronous. (I was wrong… this only proves that the event I was calling, had an animation inside it, and was calling the expected function inside the callback after the animation)

  • 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-14T04:21:29+00:00Added an answer on June 14, 2026 at 4:21 am

    You, my friend, are looking for jQuery “when”.

    http://api.jquery.com/jQuery.when/

    To force anything to be synchronous, you can use something like this….

    $.when($(this).trigger('custom-event')).done(function(){
        window.location.href = 'url';
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom event that I want to fire using jQuery's trigger method:
Is there a potential pitfall in using jquery on/off method and trigger to execute
Does anybody know of a method to trigger an event in Prototype, as you
I am using JQuery .live to listen for a custom event, ie not .click,
I want to trigger this jquery function by using trigger method of JQuery. How
I have problem when using jQuery plugin tablesorter and I can't call trigger twice.
I'm using the jQuery one() method on an event handler to fire once then
I'm using the Valums file upload pluging, and having trouble with the onComplete method/trigger/event,
I am using jQuery to try and trigger a method when an ASP.NET (2.0)
I am trying to trigger a click event on hover using jQuery. This is

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.