tags:

views:

59

answers:

4

Hi,

i insert many texarea's, and teaxarea's with tiny mce (WYSIWYG). But when i Insert this teaxarea's from this function Tiny MCS don't work. Why?

Thanks

$(document).ready(function(){
  $("#InsertNew").click(function() {
   $('<textarea id = "tinyMCE"></textarea>').appendTo($('#textBody'));
  });
 });
A: 

you mentioned you are using many text areas, the place ur trying to append to is #textBody (an id). If you are not aware, you can only have one instance of an ID per page. Instead use a classes: class="textBody" in your html then try:

$('<textarea id = "tinyMCE"></textarea>').appendTo('.textBody');
Adam
Well spot, but the problem is actually `id="tinyMCE"`.
Álvaro G. Vicario
A: 

Most likely, because TinyMCE has an initializer that scans the document looking for textareas and applies some magic on the ones that finds. Whatever you add later won't inherit this. You have to either:

  1. Re-run the TinyMCE initializer on every new item
  2. Configure TinyMCE to detect new areas

Since TinyMCE is not a jQuery plugin, I suppose you can only do #1.

Álvaro G. Vicario
Thanks, but how impossible re-run script?
lolalola
How do you run it the first time?
Álvaro G. Vicario
A: 

I think this forum post is what you are looking for.

You will need to use the jQuery live method and a trick explained at the link above.

Jochen
+3  A: 

Well your code looks like this:

<textarea id="tinyMCE"></textarea>

So what is happening here? You just add a textarea with the ID="tinyMCE" but no behaviour is added to the TextArea.

In jQuery I would expect at least the following:

<textarea class="tinyMCE"></textarea>

or event better:

$('<textarea></textarea>').tinyMCE().appendTo($('#textBody'));   

EDIT:

You might try something like this...

$('<textarea id="UniqueId"></textarea>').tinyMCE().appendTo($('#textBody'));   
tinyMCE.init({
  mode : "exact",
  elements : "UniqueId"
});

On the tinyMCE-Formus is already a diskussion going on...

http://tinymce.moxiecode.com/punbb/viewtopic.php?id=15477

Yves M.
Thanks, but i change tiny mce parameter and now work with: <textarea class = "tinyMCE"></textarea> (if i write in html). But when i put this code in my jQuery function still dos't work
lolalola