0

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

  • Two questions, why is it so that with an anonymous function the solution does not seem to work. The other, I tried implementing this in my react project, it does not seem to work there? – deadpool_216 May 20 '19 at 23:01
  • What behavior you actually want. Can you explain? – weegee May 21 '19 at 07:05

0 Answers0