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
You can do it like this, i.e. use attr instead of prop to get the string value of b's onclick, afterwards replace the arguments p,q from the string with p,q,r and then use Function constructor to create an anonymous function with the new body (after replace).
jQuery('#btn_a').on('click', function(){
var onclickB = jQuery('#btn_b').attr('onclick'),
onclickA = Function(onclickB.replace("p,q", "p,q,r"));
return onclickA();
});
Note: you can do anything with this approach, just create a regex pattern to replace anything with what you want.