0

I'm trying to make an array to tidy up my code so that I can add a bunch of event listeners to various buttons.

  for(var i = 0; i < buttoncount; i++){
    var targetid = document.getElementsByTagName("button")[i].id;
    var targetidfunc = targetid + "function";
    console.log(targetidfunc);
    document.getElementById(targetid).addEventListener("click", targetidfunc);
  }

The console has the correct function names however the event listener does not work, how can I fix this?

2
  • what is your function? Commented Nov 23, 2016 at 22:28
  • why dont directly target = document.getElementByTagName("button"); target[i].addEventListener('click', function(){alert("OK")}) Commented Nov 23, 2016 at 22:29

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.