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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T02:32:01+00:00 2026-05-30T02:32:01+00:00

Jquery bind is amazing, but I don’t know in what order the binding happens.

  • 0

Jquery bind is amazing, but I don’t know in what order the binding happens. My current problem is thus:

$(document.body).delegate('form', methods.checkForm);
$('form').bind('submit', methods.submitFormIfCheckedFormIsTrue);

methods.checkForm = function (e) {
    if (!$(this).isVerified()) {
        return false;
    }
    return true;
};
methods.submitFormIfCheckedFormIsTrue = function (e) {
    e.preventDefault();
    $.ajax("/submitForm", {
        data:$(this).serialize(),
        type:"post"
    });
};

This is obviously not the actual code that I’m using, but it’s pretty close. What happens is, the submitFormIfCheckedFormIsTrue function fires before, or during, the checkForm function, so the checking is pretty useless. My hack for it was to add the class “checked” to the form and the check if the form has that class in the other function…but then you click submit, it checks, then you have to click it again to submit it if everything went right…which is retarded.

Another thing that’s important regarding this problem is that I’m they’re in completely different parts of my application, for reasons that can’t change. Also, they’re being loaded asynchronously.

The main thing I want to know then…is how to change the order, or set the priority of the events somehow…

  • 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-05-30T02:32:03+00:00Added an answer on May 30, 2026 at 2:32 am

    If you are using ‘delegate’ the way you have it in your example, then the ajax submission is always going to run first, so the short answer to your question is “You Can’t”. Your delegate is attached to the ‘body’ element, so events attached to elements closer to the form in the DOM tree will fire first.

    Events bubble from the form -> body, so there is no ordering when you are doing that.

    One option would be to have your verification trigger a second event.

    methods.checkForm = function (e) {
      e.preventDefault()
    
      if ($(this).isVerified()) {
        $(this).trigger('form-verified');
      }
    };
    

    Then instead of binding the other handler to 'submit', you would bind it to 'form-verified'.

    $('form').bind('form-verified', methods.submitFormIfCheckedFormIsTrue);
    

    This is also another way to accomplish ordering event if they are attached to the same element instead of using delegate.

    Also, if you are using jQuery >= 1.7, then you should be using on instead of bind and delegate. http://api.jquery.com/on/

    Update

    If both are bound to the same element, then they will be triggered in the order that they were attached to the element. Assuming checkForm is bound before the other one, then the issue is that return false; does not stop other events from firing if they are attached to the same element. For that you also need e.stopImmediatePropagation().

    methods.checkForm = function (e) {
      e.preventDefault()
    
      if (!$(this).isVerified()) {
        e.stopImmediatePropagation();
      }
    };
    

    There is also a useful answer over here if you ever have to tweak the ordering of events. jQuery event handlers always execute in order they were bound – any way around this?

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

Sidebar

Related Questions

I am try to bind the dropdowmlist using jquery. But is showing some error.
today i try to make a code with jQuery bind/unbind event but, it always
Possible Duplicate: jQuery bind click ANYTHING but ELEMENT I have this HTML <div id=outer>
jQuery('img').bind('error',function(){ alert('hi'); jQuery(this).hide(); }); I have written this code but non available images are
$(document).ready(function(){ jQuery(#but1).bind(click,function(e){ alert(e.name); }); jQuery(#but1).trigger({name:'Dmy', surname:'My'}); }); The alert fails to pass the data,
Is it achievable in jquery to bind an event to a group of control
I'm having a bit of a difficulty using jQuery to bind a function to
I'm looking to find the Javascript Event I need to put into jQuery's .bind
I can bind a jquery event to this element like: <script type=text/javascript> $('#new_key').ready(function() {
With jQuery you can bind functions to an event triggered on a DOM object

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.