How can I block the inline onclick event of a button and call the function defined in that onclick later in my own click listener?
I try to inject some code which should execute before the button's onclick code is getting called.
function doSomething(el) {
console.log("doSomething was called...");
}
jQuery("#test").click(function(e) {
e.preventDefault();
console.log("click listener called...");
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<button id="test" onclick="doSomething(this)">Submit</button>