I am creating a series of buttons dynamically. How can I add a parameter to the Event Listener this.Purchase below as follows: this.Purchase(i)? Simply adding "(i)" does not work.
for (var i = 0; i < size; i++) {
var button = document.createElement('input')
button.setAttribute('type', 'submit')
button.setAttribute('value', 'Purchase')
button.addEventListener('click', this.Purchase)
}
() => this.Purchase(i)button.setAttribute('data-index', i)and use that from within the event handler instead.