Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

jQuery("#content").html()

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

Cheers

share|improve this question
    
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
add comment

1 Answer

up vote 0 down vote accepted

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:

jQuery('#content_ifr').contents().find('#tinymce').html();

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

share|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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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