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

157
Visualizações
How to add full span in content of editor?

I have these two functions: the first one is for when someone chooses an option from the select box in the toolbar add it to the content of the editor!

the code is working but it add span like this:

<span class="text-tiny">Second Side</span>

I want to when gose to editor become like this:

<span class="text-tiny" id="second_side">Second Side</span>

with id in the span

The Code

document.addEventListener("DOMContentLoaded", function() {

    forms.forEach(function(item,index) {
        var option = document.createElement('option');
        option.setAttribute("value",'<span class="text-tiny" id="'+id+item.type+'">'+item.name+'</span> <span>­</span>');
        option.innerHTML = item.name;
        select.appendChild(option);
        div.appendChild(select);
    });

    select.addEventListener('change', (e) => {
        insertHTMLAtCursor(editor,select.value)
    });
    
});

function insertHTMLAtCursor(id,value){
    // value = <span class="text-tiny" id="second_side">Second Side</span>
    const viewFragment = id.data.processor.toView(value);
    const modelFragment = id.data.toModel(viewFragment);
    id.model.insertContent(modelFragment, id.model.document.selection);
}
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