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

According to MDN

selection.anchorNode – returns the Node in which the selection begins.

selection.focusNode – returns the Node in which the selection ends.

because there were debates on naming:

  • baseNode is alias for anchorNode
  • extentNode for focusNode

Note: references to both baseNode and extentNode have been removed from the MDN page.

The following is beyond the scope of this question, but I’ll post this anyway, as I found selection to be a tricky part in some scenarios.

Take a look at this example:

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

Let’s say we’ve made selection “1234567890”.
I’ve made a picture to explain where anchor and focus nodes and offsets are.

window.getSelection

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)