0
I’m testing the Onclick on JS and I’m weirding a deal, it works only when I glue the console document.querySelector('.a').onclick = teste2();
, or the first time I run/open the page. If I click on the element that I get, it doesn’t work. Why?
<html>
<head></head>
<meta charset="utf-8">
<body>
<div class="a">Testando...</div>
<script>
let teste2 = () => alert(this === window);
document.querySelector('.a').onclick = teste2();
</script>
</body>
</html>
Caraca, I mistook it with class in PHP that I can call both with teste2 and teste2(), traveled cool... Thanks Felipe!
– Lucas de Carvalho