-2

This is my try.

tinymce.init({
    ...
});
var frame2 = '<p><div>some text<div/></p>';
tinymce.execCommand('mceInsertContent',false,frame2);

out put view on preview

<div>some text</div>

As you can see the output is wrong. The desired output is below, which is p tag wraps div which wraps the text.

<p><div>some text<div></p>

What am I missing here?

angry kiwi
  • 10,730
  • 26
  • 115
  • 161
  • It's pretty obvious, putting `
    ` inside `

    ` is incorrect HTML and therefore will be sanitized by TinyMce. So the output is correct!

    – tvgemert Jun 09 '15 at 15:06

2 Answers2

1

Try this:

var frame2 = '<p><div>some text</div></p>';

You are not closing the div tag properly. I think that's the problem which is giving you wrong output.

Also, it's good to wrap 'p' tag inside 'div' instead of 'div' inside 'p'. So if its suits your need in this case, use following:

var frame2 = '<div><p>some text</p></div>';
C.P.
  • 1,182
  • 3
  • 13
  • 32
0

Using jQuery to manipulate the final view seems to be a more elegant solution and easier. Better give up dealing with the editors.

angry kiwi
  • 10,730
  • 26
  • 115
  • 161