'how to set the order or priority of functions call in jquery or javascript?

I have problem with functions call sequence or priority in jquery or javascript.

Suppose I write different function on onclick event as you can see in the code given below where I have different functions on onclick event. like

(a) onclick delegate function
(b) onclick bind function
(c) onclick Click function
(d) onclick inLine click function .

My problem is: I want to call the delegate onclick function on top of other onclick function, means when the click event generate then the first call should be delegate onclick function not others function. There inLine onclick function which is called first by default that I don't want.

<html>
    <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">

            $(function (){                
                $("body").delegate(".track", "click", function(){                    
                    alert("Delegate called");

                });

                 $("a.track").click(function(){
                        alert("Click function called");
                 });

                 $(".track").bind("click", function (){
                    alert("Bind click called");
                });


            });



        </script>
    </head>

    <body>

        <table border="0">
            <tr>
                <td>
                    <p class="track">Click Me </p>
                    <input type="button" class="track" value="click me" />
                    <a href="http://google.com" class="track" onclick="javascript:alert('in Line on click called');">Go Google</a>
                    <br />
                    <a href="http://yahoo.com" class="track">Go Yahoo</a>
                    <br />
                    <a href="http://gaadi.com" class="track">Go Gaadi</a>
                    <br />
                </td>
            </tr>
        </table>
    </body>
</html>

Thanks for your answer.
My problem is that I want to track each and every click events on particular webpage. Suppose there is a link on which inline or external onclick event call some function or on button click or something else. I want, when a click event generates my particular function should call first which will send the ajax request and update the database that particular click event on particular link or button is generated on particular page. Now, in a site there can be many pages and on one particular page there can many links or buttons. I do not want to change or modify in existing code. I simply want a global jquery or javascript function which call on every click event and track the event before any default onclick action happens.



Solution 1:[1]

Click, Bind Delegate is the order, if inLine click comes, it goes to first.

If order is important you can create your own events and bind callbacks to fire when those events are triggered by other callbacks.

$('a.track').click(function(e) {
    // maniplate a.track ...
    $('a.track').trigger('a.track-manipulated');
});

$('a.track').bind('a.track-manipulated', function(e) {
    // do more stuff now that a.track has been manipulated
    return;
});

and for more information please look this, http://www.bennadel.com/blog/1525-jQuery-s-Event-Triggering-Order-Of-Default-Behavior-And-triggerHandler-.htm

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sameera Thilakasiri