Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

156
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda