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

314
Visualizações
How the get style of a definite position of parsed html text?

I'm trying to get the position of rich text pasted from the clipboard:

$(window).on('paste', checkClipboard);

function checkClipboard(e){
    var pastedText = e.originalEvent.clipboardData.getData('text/html');
    var parser = new DOMParser();
    var htmlDoc = parser.parseFromString(pastedText, 'text/html');
    console.log(htmlDoc);
}

For the next rich text "var parser = new DOMParser()" the result will be the following

enter image description here

In the html the tree rich text is included in spans.

How we can get the style declaration like this: "style name - style value - position from - position to"? For the example above it would be like:

{font-color: #000080, from: 0, to: 3}

{font-weight: bold, from: 0, to: 3}

{font-color: #458383, from: 4, to: 9}

...

PS: it is useless to count the length of textContent of body.firstChild.children because only spans with rich text are children, but not the plain text between the spans. So for the example above there are only 4 children.

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