Help me figure it out; I can't understand what the error is. In general, the task is the following; I need to pull an element from html by clicking on it and suppose the value of this element is output by an alert.
window.onload=function(){ gtClassName('B'); } function gtClassName(nameClass){ with(this){ ObjectAdd = document.getElementsByClassName(nameClass); ObjectAdd.addEventListener('click' , outDate); function outDate(){ alert(this); } } } I did this with jq , but it doesn't work on pure js . When sampling by id it works, and by class it gives an error in the console:
TypeError: ObjectAdd.addEventListener is not a function;
And if you specify ObjectAdd with an index, that will also work. Tell me how to make it so that the process does not require access to the cycles, otherwise how can this be done through this ?
Thank you in advance!