I am trying to enter multiple email id's into a div element. But every time I try to append Child paragraph it enters the email in the same paragraph element when the div loses focus.
I've tried to appendChild and then clear the innerHTML which removes everything which is expected. on using innerHTML+= it does create a new element but also copies the text from the previous line. This is a sample code of what I've tried
let addElement = e => {
let childElement = document.createElement('p');
childElement.innerText = e.target.innerText;
e.target.innerText = '';
e.target.appendChild(childElement)
};
<div id="textContainer" contenteditable style="border: 1px black solid" onblur="addElement(event)">
<p>ChildElement</p>
</div>
I am expecting a new paragraph to be created but instead the new text is appended onto the one paragraph