gatlanticus
gatlanticus

Reputation: 1226

How to add html tag programmatically in TinyMCE editor?

I'm using TinyMCE to edit text. When the user selects some text and presses a button, the selected section should be wrapped with <mark></mark> html tags.

The reason I'm not simply adding a custom text formatting button to the tinymce editor is because I want to trigger other actions to happen with the selected text too (i.e. copy and paste the text elsewhere).

How can I do this?

Upvotes: 0

Views: 2171

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13744

You can add your own custom button to the TinyMCE toolbar and trigger JavaScript when its clicked. You can then use the editor APIs to wrap the selected text with the tag and perform other work as needed.

Here is a TinyMCE Fiddle that shows the basic process: http://fiddle.tinymce.com/N1gaab

Upvotes: 1

Related Questions