1

I found a possibly weird behaviour of getClientRects() [getBoundingClientRect()]:

Look at this HTML code:

<p>Text here... word1<a id='id' class='class'/>word2 Other multiline Text here...</p>

[Note that the a element has no text inside, I tested just this kind of code, don't know if other arrangements give the same 'bug'.]

Let's say that when user selects a range in the p 'estate' that has the anchor inside, like "word1 word2", a JS function stores start/end elements and offsets. Next time another function creates a range with those bounds. But if getClientRects() is called on that range it yields many rects other than the two expected: first and last rects of the array indeed are the expected ones, but, between them, there are many rects that in fact cover the entire p element. [range.getBoundingClientRect() is affected too.] How to avoid this?

rdonatoiop
  • 1,185
  • 1
  • 14
  • 28
P5music
  • 3,197
  • 2
  • 32
  • 81

0 Answers0