To remove the default <p>
tag from tinyMCE content, I create a div
that stores the content coming from tinyMCE (includes <p>
tags). Then, by using find method find('p:first').html()
I retrieve the html text inside the tag. It works great, I can get rid of <p>
tags. However, with this approach, for example, the list tags ul
are just lost in the content. I have not try, but other html tags might also get lost. Do you see any problems with my code below:
var newcontent = tinymce.get('textarea_1').getContent();
//this returns a p tag that can have hold any content:
//<p>content goes here <ul><li>a</li></ul>...</p>
var mydiv = $("<div>").html(newcontent);
newcontent = mydiv.find('p:first').html();
//here I just want to get rid of <p> tag
//however I also got <ul> list items removed.
UPDATE
I tried the following code, but I got the innerHtml of mydiv
empty:
var postcontent = tinymce.get('inputPostDetails').getContent();
var mydiv = $("<div>").html(postcontent);
mydiv.replaceWith(mydiv.children());
` inside of `
– swlim Mar 22 '15 at 12:46`, refer to this [SO post about it](http://stackoverflow.com/questions/10601345/ul-element-can-never-be-a-child-of-p-element)