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

219
Visualizações
Get position from selected text in source HTML

How to get position from selected text in HTML?

the HTML content is rendered by setting innerHTML. For example 1.   2 is rendered 1. 2

The use is then selecting 2 with text selector.

const start = document.getSelection().anchorOffset

is working fine to get me the position in rendered text. Which is 5 is this case.

But is there some to get the position from HTML content (I think in this case it will be 20)

By the way great article to learn selection

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

No, that is not possible. The problem is that the DOM doesn't know about entities. It doesn't know whether the HTML source originally contained the entity or the literal Unicode character.

However you probably don't need it. You shouldn't be working with the HTML source at this point, but with the content of the DOM. You'll need to show much more code and describe the much bigger picture.

about 4 years ago · Juan Pablo Isaza Relatório
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