javascripttinymce

TinyMCE after inserting html tag using insertContent, further content is getting added inside insertedContent tag


I am trying to add a span tag dynamically with some styling using editor.insertContent method

editor.insertContent('<span style="color: red;">hello</span>&nbsp;');

I am adding &nbsp; in the end because if I don't add it and if I type new text after that it is going inside that span and getting styled as per that.

But if I want to add a comma or fullstop just after "hello" without space I am not able to do it since as soon as I delete space after hello it gets styled red.

Example link - https://fiddle.tiny.cloud/1dmG5ckf4a/2

Solutions Tried -

Expected Outcome - after inserting content dynamically new text should go outside the block which was inserted and editor styling should be resetted back to default.

TinyMCE version - v7.3.0


Solution

  • You can add zero width space &#8203; instead of &nbsp; to make it working.

    Live Demo- TinyMCE Fiddle