How to set ckeditor focus by using javascript

Hi All,

I am wondering how to set CKEditor focus by using javascript. I tried to set the input widget that replaced by CKEditor focus with javascript code like "document.getElementById(input.id).focus()". But it did nothing. I guess that because it is replaced by CKEditor and I can't access it with its original Id (input.id). So, how could I achieve that? Use CKEditor Id? Or use javascript located in CKEditor web block?

Solution

Hi Hongnan,

Try this:

$('.cke_wysiwyg_frame').contents().find('.cke_editable').focus();
Solution

Aurelio Junior wrote:

Hi Hongnan,

Try this:

$('.cke_wysiwyg_frame').contents().find('.cke_editable').focus();

Hi Aurelio,

what does '.cke_wysiwyg_frame' represent? CSS Class? 


Hi,

It's the CSS class assigned to the iframe element that contains the CKEditor text editor. So that piece of javascript first selects the iframe, then searches its contents for an element with the ".cke_editable" class and then sets the focus on it.