JSFiddle - React, Tailwind, and code Playground
HTML
<html>
<head>
<title>Hello, world!</title>
</head>
<body>
<h1>Hello, world!</h1>
<div id="target"> aaaaa </div>
</body>
</html>
JavaScript
(function() {
document.onreadystatechange = function() {
if (document.readyState === "interactive") {
try {
document.querySelector('body').addEventListener('click', function(evt) {
if (evt.target.classList.contains('some-class')) {} // not used
console.log("which", evt.which);
console.log("isTrusted", evt.isTrusted);
}, true); // Use Capturing
} catch (e) {
console.log("error on addeventlistener", e);
}
}
}
}());
//this is the autoclick code!
document.onreadystatechange = function() {
if (document.readyState === "interactive") {
el = document.getElementById('target');
if (el.onclick) {
el.onclick();
} else if (el.click) {
el.click();
}
console.log("clicked")
}
//uncomment this line below to test the second try.
//var d = document.createElement('div'); d.style.position = 'absolute'; d.style.top = '0'; d.style.left = '0'; d.style.width = '200px'; d.style.height = '200px'; d.style.backgroundColor = '#fff'; d.style.border = '1px solid black'; d.onclick = function() {console.log('hello');}; document.body.appendChild(d);
}