I managed to get the #content field html with this jquery call:


This seems to be failing though on "Add New Post" pages. Any tips on how to get the contents of the #content div?


  • It seems there is no div#content within the Add New Post page! – Hamed Momeni Nov 16 '11 at 13:49
  • I can see it <div id='editorcontainer'><textarea rows='20' class='theEditor' cols='40' name='content' tabindex='2' id='content'></textarea></div> – giorgio79 Nov 16 '11 at 13:55

The div #editorcontainer contains a regular textarea #content and an iframe #content_ifr.

The #content is filled with the saved contents of the post when the page loads. This means that any live edits of the content won't be returned when calling jQuery("#content").html(). For the same reason, you get an empty string in the case of a new post.

Where you really need to look for the live updated contents is in the iframe, which is used by the WYSIWYG editor. Here's how:


Also see: jquery/javascript: accessing contents of an iframe.

|improve this answer|||||
  • Much appreciated. Noticed this works as well tinyMCE.activeEditor.getContent(content) Wonder if there is a universal solution, as there is a CK Editor plugin as well wordpress.org/extend/plugins/ckeditor-for-wordpress – giorgio79 Nov 16 '11 at 14:48
  • @giorgio79: doesn't work for me. Returns NULL. Also if I try tinyMCE.activeEditor.getContent(content) it gets an error saying activeEditor is null do i have to enqueue any script? – Sisir Dec 15 '12 at 7:24

my code works fine in this form:

txt = $('#myTextarea')
    .replace('&lt;br data-mce-bogus="1"&gt;', '')
if (console && console.log) console.log(txt);
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.