Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide and show a CKEditor using jQuery?

The following code should allow to hide/show the CKEditor form

<a onClick="$('#form1').hide();">Hide</a>
<a onClick="$('#form1').show();">Show</a>
<form action="sample_posteddata.php" method="post" id="form1">
    <textarea id="editor1" name="editor1">blabla</textarea>
    <script type="text/javascript"> CKEDITOR.replace( 'editor1' ); </script>
    <input type="submit" value="Submit" />
</form>

However, this code works fine on Chrome but on Firefox, once I have toggled once the editor (one 'hide' click followed by one 'show' click) , it becomes not editable !!

How can I make it work on every browser?

Thank you.

like image 865
fabien7474 Avatar asked Jul 16 '10 23:07

fabien7474


People also ask

How can I get the content of CKEditor using jQuery?

You should use getData() method to get data from CKEDITOR.

Does CKEditor use jQuery?

CKEditor 4 offers native jQuery integration through its jQuery Adapter (a jQuery plugin basically). It provides deep integration of CKEditor 4 and jQuery that lets you use the native features of jQuery when using CKEditor 4.

How do you call CKEditor in HTML?

To start, create a simple HTML page with a <textarea> element in it. You will then need to do two things: Include the <script> element loading CKEditor 4 in your page. Use the CKEDITOR.

What is CKEditor replace?

The CKEditor 4 Find and Replace feature allows for finding and replacing any text in the editor easily. It helps the user find words, word parts or phrases matching the case of the searched text, which is especially helpful in lengthy documents and one that may utilize certain words in different contexts.


1 Answers

Solution is:

// Hide form
CKEDITOR.instances.editor1.updateElement();
CKEDITOR.instances.editor1.destroy();
$('#form1').hide();
//Show form
CKEDITOR.replace( 'editor1', {height: "220px", skin: "v2"});
$('#form1').show();
like image 81
Peyote Avatar answered Sep 28 '22 14:09

Peyote