javascript - What is anchorNode , baseNode , extentNode and focusNode in the object returned by document.getSelection? -


if make selection in html page , :

var = document.getselection() 

i object 4 properties :

  1. anchornode
  2. basenode
  3. extentnode
  4. focusnode

the values of first 3 same i.e. text have selected how different , 1 use?

according mdn

selection.anchornode - returns node in selection begins.

selection.focusnode - returns node in selection ends.

because there debates on naming, basenode alias anchornode, extentnode focusnode

the following beyond scope of question, i'll post anyway, found selection tricky part in scenarios.

take @ example:

<p>ab12<sup>3</sup>4567890 !</p> 

let's we've made selection "1234567890". i've made picture explain anchor , focus nodes , offsets are.

window.getselection


Comments

Popular posts from this blog

ruby on rails - RuntimeError: Circular dependency detected while autoloading constant - ActiveAdmin.register Role -

c++ - OpenMP unpredictable overhead -

javascript - Wordpress slider, not displayed 100% width -