DOM button is getting clicked with .click() method, but its not working on document itself.
/* Working fine */
function getAlert() {
alert("Clicked!!!");
}
var btn = document.getElementById('btn');
btn.onclick = getAlert;
btn.click()
/* Should be work */
document.onclick = getAlert;
document.clicked()
<button id="btn">Click Me!</button>
Please help.
document objects are not things that can be clicked on.
Event handlers can be bound to a document, and events will bubble until they reach the document and trigger a handler, but you can't click directly on the document.
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