Can't figure out which function called when <p>There is an <code>elements</code> object, which is not Array but array-like HTML object.<br> I need to <code>alert</code> <code>innerHTML</code> of each <code>element</code> in 1 second after <code>click</code> on it.<br> I wrote this code (below), but it doesn't work.</p> <pre><code>[].forEach.call(elements, function (element) { element.onclick = () =&gt; setTimeout(alert(element.innerHTML), 1000); }); </code></pre> <p>I intuitively know that there is an error in this code (even without its execution), but I don't know where and what is it like (something wrong with arguments maybe?).<br> Use of <code>forEach</code> is mandatory (indexer <code>i</code> is used in original code).</p> <hr> <p>Perhaps omitting insignificant details of the problem, I missed something meaningful. So I bring a more complete piece of code:</p> <pre><code>var colors = ["red", "green", "blue"]; var fragment = document.createDocumentFragment(); colors.forEach(function (color, i) { var span = document.createElement("SPAN"); span.style.backgroundColor = color; span.tabIndex = i + 1; span.onclick = () =&gt; setTimeout(console.log(span.innerHTML), 1000); fragment.appendChild(span); }); </code></pre>