I am using innerHTML to add some elements and wrapper on top of it
for (i = 0; i < arr.length; i++) {
b.innerHTML += "<div class='wrapper'><div class='col-4'>" + arr[i].storeID + "</div>" +
"<div class='col-4'>" + arr[i].Bookid + "</div>" +
"<div class='col-4'>" + arr[i].StoreName + "</div>" + "</div>"
var d=document.querySelector('.wrapper')
d.addEventListener("click", function(e) {
console.log('on click fired')
/*insert the value for the autocomplete text field:*/
inpStr=this.innerHTML
inp.value = this.innerHTML
/*close the list of autocompleted values,
(or any other open lists of autocompleted values:*/
closeAllLists();
});
}
The innerHTML
is working as expected but when I click the wrapper
row, I get
Cannot Cannot read property 'addEventListener' of null when using innerHTML
Is this because I am using innerHTML to create an element?