0

here is HTML:

<div class="args-container">
    <button type="button" id="nuclear">click to see nuclear</button>
    <button type="button" id="geothermal">click to see geothermal</button>
</div>

here is javascript:

const args = Array.from(document.querySelector(".args-container").children);

args.forEach(e => e.addEventListener("click", myFunc()));

If i click on a button "myFunc()" isn't working

  • 3
    The second argument to `addEventListener()` should be a **reference to a function**. You're passing in the *result* of calling `myFunc()`, not a reference to `myFunc()`. – Pointy Apr 25 '22 at 19:49
  • Duplicate of https://stackoverflow.com/questions/15886272/what-is-the-difference-between-a-function-call-and-function-reference – Jakub Kotrs Apr 25 '22 at 19:49

0 Answers0