I have the following situation:
In a html page i have a dynamically generated button, similar to:
<div id='myButton'></div>
This html page includes a script (e.g., A.js), that handles most of the functionality of the site, and in this script the button is being bound to an handler:
$("#myButton").bind("click", function(){
foo();
});
So far its simple. Now, only in a particular situation, i need the same button to execute a second function. This has to be done through another script, dynamically generated and injected inside the html site. So the html will look similar to this:
<script type=text/javascript src=A.js></script>
<script type=text/javascript>
//Dynamically generated script
</script>
I do not want to override the previous function, i still need that to be executed, but also i need this function to be executed before the first one. And the way scripts are included on the site cannot be changed.
So, I have written the following (inside the second script tag):
$("#myButton").bind("click",
function(){
bar(); // I still want foo() to be executed but after this is executed first.
});
Is it possible to do something like this? Note that i do not have control on how scripts are included on my site. Altering that order is not possible.