Unable to get CKEditor w / jQuery value

I refer to the CKEditor jQuery adapter (and also to jquery 1.6 lib)

<script type="text/javascript" src="../ckeditor/ckeditor.js" /> <script type="text/javascript" src="../ckeditor/adapters/jquery.js" /> 

And announcing that my CKEditor instance is:

 <textarea id="editor1" name="editor1"></textarea> <script type="text/javascript"> CKEDITOR.replace( 'editor1', { toolbar : 'Basic', uiColor : '#0579b3', resize_enabled: false }); </script> 

In jQuery I do:

 var value = $('textarea.editor1').getData(); 

If I try to warn the value of var, I get undefined.

Is there something wrong with the way I'm trying to get the textarea w / jQuery value? I also tried .val () but no luck.

A warning occurs after a button is pressed.

+7
source share
2 answers

Try:

 var value = CKEDITOR.instances['editor1'].getData(); //or $('#editor1').ckeditor(function( textarea ){ $(textarea).val(); });
var value = CKEDITOR.instances['editor1'].getData(); //or $('#editor1').ckeditor(function( textarea ){ $(textarea).val(); }); 

Hope this helps

+19
source

You can integrate the function in jQuery

 jQuery.fn.CKEditorValFor = function( element_id ){ return CKEDITOR.instances[element_id].getData(); } 

and passing the ckeditor id element as a parameter

 var editor1_value = $().CKEditorValFor('editor1'); 
+2
source

All Articles