10

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.

0

2 Answers 2

20

Try:


var value = CKEDITOR.instances['editor1'].getData();

//or
$('#editor1').ckeditor(function( textarea ){
  $(textarea).val();
});

Hope it helps

Sign up to request clarification or add additional context in comments.

1 Comment

I tried the first one and worked for me, calling the element ID without the #, as you created the CKEditor element.
3

You could integrate a function on JQuery

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

and passing as a parameter the ckeditor element id

var editor1_value = $().CKEditorValFor('editor1');

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.