I am trying to intercept the click of a button to do something before and after.
How to trigger the original click?
const el = document.querySelector(selector);
if (!el) { return; }
# Save original onclick
const onclick = el.onclick;
# Change onlick
el.onclick = async function (event) {
console.log('Before click');
# TODO: call the orignal onclick? <-------- ???
onclick.call(event);
console.log('After click');
}
I get the following output
BEFORE CLICK
Uncaught (in promise) TypeError: onclick is null