How to get text data from froala editor?

Viewed 9354

Currently I use $('div#edit').froalaEditor('html.get') to retrieve the html data inside editor, but it sucks when it comes to process / store the text data in my backend because of all the p tags and &npsb; symbols in raw html string.

To be honest they do not even pass to the database without losing parts of the data. Is there a way or an api to directly extract the text data as a string with proper symbols like "\n\t" from the froala editor?

4 Answers
  1. If you dont like p tags you should use the enter option:

    $('div#froala-editor-br').froalaEditor({
      enter: $.FroalaEditor.ENTER_BR
    });
    
  2. If you really would like to remove all tags you could use jQuery text method

    jQuery($('div#edit').froalaEditor('html.get')).text()
    
  3. Or you could use HTML options

    var html = $('div#edit').froalaEditor('html.get') ;
    var div = document.createElement("div");
    div.innerHTML = html;
    alert(div.innerText); 
    

Honestly, the easiest way to do this is

var body = $('#body').froalaEditor('html.get');
alert($(body).text());
Related