I have more than 30 addEvent listeners i need to add to my WebApp. But the Code to dynamically add them is not working, unless change:
to
but obviously hardcoding all of those DIV IDs would defeat the purpose of the code.
Code in Question:
Code:
AddItemEvtAry[x].addEventListener('click', function (e) {document.getElementById("text" + x).value ++}, false);
Code:
AddItemEvtAry[x].addEventListener('click', function (e) {document.getElementById("text0").value ++}, false);
but obviously hardcoding all of those DIV IDs would defeat the purpose of the code.
Code in Question:
Code:
// Event Listeners for Incrimenting Quantities var AddItemEvtAry = [40]; for(var x = 0; x < 39; x++) { AddItemEvtAry[x] = document.getElementById("AddItem" + x); } for(var x = 0; x < 39; x++) { AddItemEvtAry[x].addEventListener('click', function (e) {document.getElementById("text0").value ++}, false); }
Comment