I have a button created through javascript but I can't assign the function to the button.
The function works when I make it an onclick not assigned to any button so I know I'm probably formatting something wrong.
Any help is appreciated.
JS code
var tickButton;
for (tickButton = 0; tickButton < myNodelist.length; tickButton++) {
  var span = document.createElement("SPAN");
  var txt = document.createTextNode("\u2713");
  span.className = "tick";
  span.appendChild(txt);
  tickButton.onclick = function(){
    alert('hello');
  };
  myNodelist[tickButton].appendChild(span);
}
 
     
     
    
- Hit the gym
- Pay bills
- Meet George
- Buy eggs
- Read a book
- Organize office
` – GagGreene Aug 18 '22 at 15:41