I have this dynamically created button that works fine and the innerHTML looks like this:
inboxEmail.innerHTML = `
<strong>${email.sender}</strong><br>
${email.subject}<br>
${email.body}
`;
This functions just as I expect it to. I wanted to change the way text was displayed inside the button which I managed to do successfully by changing the innerHTML to this:
inboxEmail.innerHTML = `
<div class="container">
<div class="row">
<div class="col-10">
<strong>${email.sender}</strong><br>
${email.subject}<br>
${email.body}
</div>
<div class="col-2">
${email.timestamp}
</div>
</div>
</div>
`;
Now this button is not functioning at all. This is the onclick function:
document.querySelector('#emails-view').addEventListener('click', function(e) {
if(e.target && e.target.nodeName == 'BUTTON' && isNaN(e.target.id) === false) {
alert(e.target.id);
emailSelect(e.target.id);
} else {
console.log('error')
return false;
}
})
Instead the 'error' is showing on the console. I have not touched the inboxEmail.id only the innerHTML so why isn't it working?
EDIT: This is my "emails-view" copied from my Inspect Element on the page:
<div id="emails-view" style="display: block;"><h3>Inbox</h3>
<div class="list-group">
<button class="list-group-item list-group-item-secondary list-group-item-action" id="7">
<div class="row">
<div class="col-10">
<strong>monday@example.com</strong><br>
RE: very important<br>
Hi
I hope y...
</div>
<div class="col-2">
Oct 16 2020, 08:13 PM
</div>
</div>
</button></div></div>