For some reason, I need two windows onclick event on one page
window.onclick = function(event) {
alert("abc")
}
window.onclick = function(event) {
console.log("abc");
}
but only the second one run. Any idea how I can make both works.
You are overwriting window.onclick
so only the latter will run. You should use addEventListener instead if you want to use vanilla JS.
window.addEventListener('click', function(event) {
alert("abc")
});
window.addEventListener('click', function(event) {
console.log("abc");
});
If you are using jquery, then you can use jQuerys .click.
$(window).click(function(event) {
alert("abc")
});
$(window).click(function(event) {
console.log("abc");
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With