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

319
Vistas
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 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