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

151
Views
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
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!