First off I'll start off by saying I am new to javascript so hopefully this isn't a complete face palm question. That being said, the following code should alert the value of the editor when the user clicks off of it.
<script type='text/javascript'>
function openEditor(){
html = Hello World;
config = {
startupFocus : true
};
editor = CKEDITOR.appendTo( 'textBox', config, html );
if (editor) {
editor.on('blur', function(event) {
var ckvalue = CKEDITOR.instances.editor.getData();
alert(ckvalue);
});
}
}
</script>
<html>
<a href='#' onclick='openEditor()'>Open Editor</a><br />
<div id='textBox'></div>
</html>
Instead google chrome console reports:
Uncaught TypeError: Cannot call method 'getData' of undefined
Now when I change
var ckvalue = CKEDITOR.instances.editor.getData();
to
var ckvalue = CKEDITOR.instances.editor1.getData();
It works. This baffles me because I never declared a editor1 instance. I was hoping someone with a little more experience could explain to me why editor1 works when editor doesnt.
Here is a working example of what Im talking about: http://jsfiddle.net/s3aDC/6/