Range collapses when startOffset is after the last character

By design Issue #15684911


Kelly P.
Jan 29, 2018
This issue is public.
Found in
  • Microsoft Edge
Found in build #
Reported by 1 person

Sign in to watch or report this issue.

Steps to reproduce

When setting the startOffset of a Range, if you set it to the length of the child nodes, it collapses to the endOffset.

var node = document.querySelector('#last')
var text = node.firstChild
var selection = document.getSelection()
var range = document.createRange()

// Create a range where the startOffset is the length of the node:
range.setStart(text, text.length)
range.setEnd(text, 1)

// The range will collapse to the endOffset
console.log(range.startOffset, range.endOffset)




0 attachments

    Comments and activity

    • Microsoft Edge Team

      Changed Assigned To to “Steven K.”

    • Hi Kelly,

      I believe this is proper behavior for a range set with the start position lower in the document/text than the end position.  E.g. start is a higher number than the end.


      “Setting the start point below (lower in the document) the end point will result in a collapsed range with the start and end points both set to the specified start position.”

      I believe this might be confusing due to the anchor and the offset in the selection API allowing either ordering.


      "A user may make a selection from left to right (in document order) or right to left (reverse of document order). The 

      is where the user began the selection and the 

      is where the user ends the selection. If you make a selection with a desktop mouse, the anchor is placed where you pressed the mouse button and the focus is placed where you released the mouse button. Anchor and focus should not be confused with the start and end positions of a selection, since anchor can be placed before the focus or vice versa, depending on the direction you made your selection."


    • Ah, my mistake.

    • Microsoft Edge Team

      Changed Status to “By design”

    • Thanks for the quick response and of course, no worries.  Apparently, this happens enough to warrant a note in the documentation.  :)

      Thank you for the submission and the support,

      The MS Edge Team

    You need to sign in to your Microsoft account to add a comment.

    Sign in