Inserting content in tinymce, additional text is placed inside inserted content

I've got a video upload for tinymce, which inserts some code into the editor like so:

var content2 = "<div class='playvideo' id='<?php echo $randomnumber;?>'>
<img class='posterimage' src='<?php echo $new_image_path; ?>'>
<a id='<?php echo $new_file; ?>' class='videoplaceholder'></a>

parent.tinyMCE.execCommand('mceInsertContent', false,content2);

this works fine, and outputs this :

<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />
<a class="videoplaceholder" id="1097VID.mp4"></a>

But after this content is inserted, ofcourse I would like to continue writing text. But when I do that, the text gets placed inside my inserted content after the img tag. like so:

<p><div id="581827" class="playvideo">
<img class="posterimage" src="/uploads/videos/images/1097VID.jpg" alt="" />text i try to write goes here for some reason
<a class="videoplaceholder" id="1097VID.mp4"></a>

Fiddle example

When enter is clicked for new line, it creates a second div with the same class as what I inserted. It's a weird behavior.. I read that a div is illegal inside a paragraph, but it doesnt work with span either.

Does anyone have any pointers? Any help is greatly appreciated.


The problem of the text getting inserted after the img can be fixed by putting an &nbsp; as the link text i.e. instead of <a id='<?php echo $new_file; ?>' class='videoplaceholder'></a> you can use <a id='<?php echo $new_file; ?>' class='videoplaceholder'>&nbsp;</a>. I am not sure about the class though, may be there is a way to prevent TinyMCE from adding the class by default.

Need Your Help

jQuery - Show and hide last 4 numbers of a phone number

javascript jquery

How can I show and hide the last 4 numbers of a phone number by replacing it with something like 949XXXX and when you click on it show the rest of the numbers?

how to run an exe file on windows server from a website thats all?

php windows server web windows-server-2008

Hello all please help me with this i have a windows server which i can access with RDP and i can see the whole windows xp i have a exe file in "c" drive there under the folder name exe and i want t...