You probably need to save the contents of your editor somewhere:
var html = $(this).froalaEditor('html.get');
And then just separate the HTML tags if I understand you correctly. The easiest way is with the jQuery.text () method :
var text = $( html ).text();
Update
Do you need to remove only the top-level <p>
tags? Here is a function that implements the filtering of these tags using jQuery. But you can rewrite it and create an array of exception tags, or call it recursively for each child content element. Alternatively, you can use regular expressions as an alternative.
function stripParagraphs( html ) { var r = ''; $( html ).each(function() { // test each higher-level tag to be <p> if ($( this ).prop( 'tagName' ) === 'P') { r += $( this ).html(); // add contents of <p> to result } else { r += this.outerHTML; // add the whole element to result } }) return r; }
Living example .
another update
Remove all top level tags.
function stripTopLevelTags( html ) { var r = ''; $( html ).each( function() { r += $( this ).unwrap().html(); }); return r; }
Real time example
source share