Remove leading and trailing white spaces in TinyMCE text area

I'm trying to remove leading and trailing white spaces in TinyMCE text area.

var frontandbackremovedhere = tinyMCE.get('ID').getContent().trim();

I tried above but not working.how can I do this

for example

If I inset following text in editor

    Hi,          


Regards


kez     

It will get the html as following

<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Hi,<br><br>Regards<br><br></p><p>kez &nbsp; &nbsp; &nbsp; &nbsp;</p>

I'm trying to remove it like this

<p>Hi,&nbsp; &nbsp;<br><br>Regards<br><br></p><p>kez</p>

Answers 1

  • Let editorContent = tinyMCE.get('ID').getContent({format:'raw'}).trim();
    tinyMCE.get('ID').setContent(editorContent);
    

Related Articles