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

295
Visualizações
Anyway for getSelection method to ignore html tags

I want to save the range and after reload of page use those values for highlighting ( with yellow color for ex.) but the problem is getRangeAt(0) does not return range correctly. it's ranges restart after any html tags, how can i solve this problem?

<p id="content">
  hello <br> John 
</p>

document.addEventListener("selectionchange", () => {
  $("#content").bind("touchend mouseup", function() {
    var t = window.getSelection();
    var range=t.getRangeAt(0);
    var text=t.toString();
                    
    if(text! = "") {
      var rect = range.getBoundingClientRect();
      var start=range.startOffset;
      var end=range.endOffset;
      console.log(start, ' = ', end);
    }
  });
});

in this case getRangeAt(0) return 0,4 if i select "hello", then if i select "John" it returns 0,4 again .

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