How do you set the focus of a TinyMCE textarea element?

Justin picture Justin · Feb 6, 2010 · Viewed 54.3k times · Source

I'm using TinyMCE for a textarea on a page but it doesn't play nice in the tabbing order of the other elements.

I can use the following code to capture when I tab out of the first element:

$('#title').live('keypress', function (e) {
   if(e.keyCode == 9) {
       alert('tabbed out');
   }
});

How can I set the focus to a TinyMCE editor?

Answer

jbnunn picture jbnunn · Apr 22, 2010

Finally found an answer... use the command:

tinymce.execCommand('mceFocus',false,'id_of_textarea');

For my purposes, 'id_of_texterea' was "description", ie

<textarea id="description" ... ></textarea>

In the form element that preceded my textarea, I added the execCommand above to the element's "onblur" action.