Viet Viet - 1 year ago 160
jQuery Question

Appending text to text area using WYSIHTML5 and jQuery

I'm using the latest (0.3.0) version of WSYIHTML5 for a message board. One of the features of the board is a quote post option. I've been trying to figure out how to append the quote to the text area.

I have the following jQuery as a test

$('textarea').append('test this');

The alert shows the text has appended to the hidden textarea, but it does not update in the iframe of the WYSIHTML5 view.

What's weird is if I straight up append the text after initializing the WYSIHTML5, it appends just fine.

Any ideas on getting this to work?

Answer Source

So in order to update the iframe and have it format any text with HTML, I did the following..

var value = editor.getValue();
var text = '<b>some text</b>;'
editor.setValue(value + text, true);

This is assuming WYSIHTML5 is instantiated under the variable 'editor'. It'll append the quote, plus format the text correctly. The boolean value is if you want the value to be run through the WYSIHTML5 parser rules.

If anyone knows a better way of doing it, I'm all ears.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download