Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

133
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda