Belinda
Belinda

Reputation: 1231

CKEDITOR.replace() is hiding the textarea that I want converted

I'm using Javascript to create a textarea that I want to be a ckeditor. My code is something like

var html = '<textarea name="text"></textarea>';
$('#mydiv').append(html);  
var textareas = document.getElementsByTagName('textarea');  
// Could be more than one textarea   
for (i = 0; i<textareas.lenght; i++) {  
    var textarea = textareas[i];  
    CKEDITOR.replace(textarea.name); 
}

When I run this code and check the output the textarea is hidden. Inspecting it in firebug I'm getting a style="visibilty:hidden". However removing this just gives me a textarea and not a ckeditor. Does anyone have any suggestions on how to solve it.

Putting it as a div worked but the examples all seemed to be in textareas.

Upvotes: 1

Views: 10754

Answers (1)

jigfox
jigfox

Reputation: 18185

The hiding is correct. Because the <textarea/> has no wysiwyg support. The .replace() method replaces the <textarea/> with it's wysiwyg Editor. That's why it's hidden.

CKEDITOR.replace(elementOrIdOrName, config)
Replaces a or a DOM element (DIV) with a CKEditor instance. Source

As you can see in the documentation you don't need to append the <textarea/>, instead you could use your div directly:

CKEDITOR.replace('mydiv')

Upvotes: 1

Related Questions