JavaScript: get the sender element
<p>I have this code:</p>
<pre><code>var x = document.getElementsByClassName(&quot;hex&quot;);
     
for(var i = 0; i &lt; x.length; i++)
{
    x[i].addEventListener(&quot;click&quot;, myFunction);
}
</code></pre>
<p>To attach onclick dynamically. My question is <code>myFunction</code> how to get the clicked element?</p>