Points to be noted:
- The whole document is
content editable
- The body has an
input event
attached to it - I need to get the id of the specific element which was changed
- Only vanilla Javascript is allowed
e.g : If I change Tom
to Paul, I should get m1
as id.
Problem: e.target
returning the body element instead specifc element(div#m1
)
document.body.contentEditable = true;
document.body.addEventListener('input', e => {
console.log(e.target)
})
<div id="m1">Hello Tom</div>
<div id="m2">Hello Sam</div>