Search code examples
jqueryckeditor

Cannot get CKEditor value w/ Jquery


I am referencing the CKEditor JQuery adapter (as well as jquery 1.6 lib)

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

And declaring, my CKEditor instance as:

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

In Jquery I am doing:

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

If I try to alert the var value, I get undefined.

Is there something wrong with how I am trying to get the textarea value w/ JQuery? I have also tried .val() but no luck.

The alert happens after a button is pressed.


Solution

  • Try:

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

    Hope it helps