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

172
Visualizações
When does `getTargetRanges()` return more than one range?

When using a beforeinput of type InputEvent you can query the getTargetRanges() which return an array of static ranges that will be affected by the input event.

What's an example scenario in which getTargetRanges() will return more than one range? Or does it return an array 'just in case' there will be such an event in the future? Reason for asking is that I would like to properly test code that relies on the return value of getTargetRanges().

MDN: https://developer.mozilla.org/en-US/docs/Web/API/InputEvent/getTargetRanges
Spec: https://w3c.github.io/input-events/#overview


Playground:

document.querySelector('div').addEventListener('beforeinput', (event) => {
  console.log(event.inputType, event.getTargetRanges().length);
  if (event.getTargetRanges().length > 1) {
    alert('how?');
  }
})
<div contenteditable>
  <p>Hello world</p>
  <p>This is a tyypo</p>
</div>

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

0

Multiple selections are one example. E.g. in Firefox, double-click on a word, hold down Ctrl/Command, double-click on another word, backspace.

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