Madness
Madness

Reputation: 638

TinyMCE 4 - Plain text/strip HTML tags button

Is there a way to completely strip the selected elements of their styles AND HTML tags?

So <p>Text</p> would become Text.

Either using a custom button (function), or a 'Plain Text' style in the formats dropdown?

Upvotes: 2

Views: 2453

Answers (2)

Madness
Madness

Reputation: 638

Thanks to Anub for direction, I managed to do this myself.

// Store the current selections string/value in a variable and strip it's tags
var node = tinymce.activeEditor.selection.getContent({ format : 'text' });

// Replace the selected content with the stripped out content
tinymce.activeEditor.selection.setContent(node);

Upvotes: 3

Ayoub Bousetta
Ayoub Bousetta

Reputation: 97

try

selection.getContent({format : 'text'});

or

selection.getContent({format : 'html'});

Upvotes: 4

Related Questions