How do I set a WYSIWYG's value with javascript? does the WYSIWYG module provide an api for this?

I don't know which editor user is using, so I can't use the api of editors.

  • by WYSIWYG's value you mean the content of the textarea?
    – jonhattan
    Commented Nov 1, 2013 at 13:34
  • @jonhattan Yes!
    – Nima
    Commented Nov 1, 2013 at 22:17
  • 1
    You don't want to hook on hook_form_alter I guess ? Commented Nov 2, 2013 at 13:55
  • @GregoryKapustin Content should be inserted by javascript
    – Nima
    Commented Nov 2, 2013 at 17:35
  • Any reason why you want the content to be inserted by JavaScript?
    – Randell
    Commented Nov 6, 2013 at 9:19

1 Answer 1


The following code worked perfectly fine for me,

(function($) {
    $(document).ready(function() {
      $("#edit-body-und-0-value").val('this is a test content.');

I have placed this code is test.js file. 'edit-body-und-0-value' is the ID of the textarea.

I have installed WYSIWYG module and placed CKEditor under sites/all/libraries/ckeditor folder. Although it doesn't matter if you are using CKEditor or any other editor because we are mainly referring to ID of our textarea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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