I'm using this code however from onclick
it does not work if I click on the "fa-search" element, however if I paste the same JS into the chrome console it works as expected.
I wonder why? I imagine it's something that is scope related.
onload = (() => {
console.log("agua");
document.getElementsByClassName("fa-search")[0].onclick = () =>{
document.getElementById("fieldSearch").focus();
console.log("Executou");
}
})();
<html>
<head>
<script defer src="https://use.fontawesome.com/releases/v5.6.1/js/all.js"integrity="sha384-R5JkiUweZpJjELPWqttAYmYM1P3SNEJRM6ecTQF05pFFtxmCO+Y1CiUhvuDzgSVZ" crossorigin="anonymous"></script>
</head>
<body>
<aside id="container">
<header>Encontre um ponto de venda</header>
<p>Digite o seu CEP, rua, bairro ou cidade</p>
<div class="search">
<input type="text" id="fieldSearch">
<i class="fas fa-search"></i>
</div>
<div id="proximidade">
<ul>
<li>
<button>5 KM</button>
</li>
<li>
<button>10 KM</button>
</li>
<li>
<button>15 KM</button>
</li>
</ul>
</div>
<div id="block-list">
<i class="fas fa-list"></i>
<span>Lista</span>
</div>
</aside>
</body>
<link rel="stylesheet" type="text/css" href="Dist/my-styles.css" />
<script src="../Sass/js/mapa.js"></script>
</html>