Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

132
Views
Tinymce - removing existing tags when adding new tag

I created a new button in the TinyMCE toolbar. Its purpose is to add a new class on selected the text. It's working, but in some cases the existing tag is replaced when adding the new class.

For example:

<p> dummy text dummy text <strong> dummy text </strong> <p>

Some times the strong tag is removed if I select the content in the strong tag. This doesn't only happen on strong tags though, span, em, u tags too.

setup: function(editor) {
  editor.addButton('addClasses', {
    menu: [{
      onclick: function(e) {
        let ed = tinyMCE.activeEditor;
        let content = ed.selection.getContent({
          'format': 'html'
        });
        let new_selection_content = `<span class="text-${color}">${content}</span>`;
        ed.execCommand('mceInsertContent', false, new_selection_content);
      }
    }
  }
}

I have to keep the existing tags and just want to add the new class on the selected text. How can I achieve my task?

For reference I'm using TinyMCE version 4.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!