In my application I have alot of anchor tags and buttons and most of them have event called by onclick on the element.
what I want is to call a function before any other functions are called.
html
<input type="button" value="add" onclick="add()">
<input type="button" value="sub" onclick="sub()">
<input type="button" value="div" onclick="div()">
js
function add(){
alert("add");
}
function sub(){
alert("sub");
}
function div(){
alert("div");
}
$(document).on("click","input[type=button]",function(){
alert("bye");
});
here is the fiddle fiddle
I supposed that
$(document).on("click","input[type=button]",function(){
....
});
will be called first so that I can process something before
function show(){
alert("hi");
}
is called , but that is not true. what should do to accomplish this.
I want to call a function on all anchor tags and buttons, even before the
onclick="show()"
Update
I have updated the fiddle
P.S
each element have its own function to call , but the function in $(document) is same which i want to call on all element filtered by. I have suggestions that why not to make a function having logic of $(document) I have and call it on all functions called by elements i.e add(),sub(),div(). But ans is no I can not , because it is just a demo my real application is quit large and cannot figure each function and call other function. thats why I want an alternative.
onclickand put theshow()inside the jQuery click handler?