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

  • Home
  • SEARCH
  • 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 5957487
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:24:26+00:00 2026-05-22T18:24:26+00:00

Lets say I have a web app which has a page that may contain

  • 0

Lets say I have a web app which has a page that may contain 4 script blocks – the script I write may be found in one of those blocks, but I do not know which one, that is handled by the controller.

I bind some onclick events to a button, but I find that they sometimes execute in an order I did not expect.

Is there a way to ensure order, or how have you handled this problem in the past?

  • 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-22T18:24:27+00:00Added an answer on May 22, 2026 at 6:24 pm

    I had been trying for ages to generalize this kind of process, but in my case I was only concerned with the order of first event listener in the chain.

    If it’s of any use, here is my jQuery plugin that binds an event listener that is always triggered before any others:

    ** UPDATED inline with jQuery changes (thanks Toskan) **

    (function($) {
        $.fn.bindFirst = function(/*String*/ eventType, /*[Object])*/ eventData, /*Function*/ handler) {
            var indexOfDot = eventType.indexOf(".");
            var eventNameSpace = indexOfDot > 0 ? eventType.substring(indexOfDot) : "";
    
            eventType = indexOfDot > 0 ? eventType.substring(0, indexOfDot) : eventType;
            handler = handler == undefined ? eventData : handler;
            eventData = typeof eventData == "function" ? {} : eventData;
    
            return this.each(function() {
                var $this = $(this);
                var currentAttrListener = this["on" + eventType];
    
                if (currentAttrListener) {
                    $this.bind(eventType, function(e) {
                        return currentAttrListener(e.originalEvent); 
                    });
    
                    this["on" + eventType] = null;
                }
    
                $this.bind(eventType + eventNameSpace, eventData, handler);
    
                var allEvents = $this.data("events") || $._data($this[0], "events");
                var typeEvents = allEvents[eventType];
                var newEvent = typeEvents.pop();
                typeEvents.unshift(newEvent);
            });
        };
    })(jQuery);
    

    Things to note:

    • This hasn’t been fully tested.
    • It relies on the internals of the jQuery framework not changing (only tested with 1.5.2).
    • It will not necessarily get triggered before event listeners that are bound in any way other than as an attribute of the source element or using jQuery bind() and other associated functions.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have a web page that currently accepts a single ID value
I have a web app that has lots of pages with a URL of
Let's say you have a typical web app and with a file configuration.whatever. Every
Let's say I have a class in my web app called class Foo. It
Let's say I have a list of categories for navigation on a web app.
Lets say I have several web sites on my web server, all as applications
When creating a web application, and lets say you have a User object denoting
Let's say I have a web site for hosting community generated content that targets
Lets say we have a web based application where users login to their own
I have written a personal web app that uses charCodeAt() to convert text that

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.