Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!