I am having 2 buttons A & B and I need to call the function defined in onclick HTML attribute of button B but on click of button A.
Also I need to pass an extra param to that function in this case. buttons are like:
<input type="button" id="btn_a">
<input type="button" id="btn_b" onclick="return doSomething(p,q)">
I want to make a call like:
doSomething(p,q,r) // 3rd param to identify that it was clicked via button A
Button B is actually a variable button & gets the p,q params dynamically & I need to pass the 3rd param along.
button B can have onClick attribute like
onClick= return doSomething(122,334) or return doSomething(abc,54)
or any other values. I need to call the function such that
doSomething(122,334,'btn_a') or
doSomething(abc,54,'btn_a')
how to achieve this using jQuery/JS? I was able to call the function using the .prop()
but couldn't figure out passing the additional param.
I was able to call the function like:
<script>
jQuery('#btn_a').on('click',function(){
(jQuery('#btn_b').prop('onclick'))(); //this can invoke the function but how to pass the additional param?
})
</script>
thanks in advance. :)