Recovering Nerdaholic
Recovering Nerdaholic

Reputation: 707

deinit/reinit tinyMCE on dynamically generated DOM

I have an SPA that dynamically loads routes via AJAX and generates the DOM from the output. Once it's rendered, tinymce is initialized into the appropriate element(s).

The problem is that this tinymce only initializes on the actual page load.

How I do I get tinymce it to reinitialize when the DOM is dynamically reloaded?

I've tried using mceRemoveEditor and mceAddEditor on the appropriate triggers, but it has no effect and reports no errors.

Upvotes: 1

Views: 2730

Answers (1)

Recovering Nerdaholic
Recovering Nerdaholic

Reputation: 707

SOLUTION:

Unload tinymce on any initialized elements before unloading current DOM containing the tinymce elements.

if (typeof tinymce != 'undefined' && tinymce != null) {
        tinymce.remove([selector]);
}

Then you can run tinymce.init() after loading a new route and generating new DOM elements.

Upvotes: 2

Related Questions