Can a DOM Range object end before it starts?
The DOM specification on Range objects doesn't address whether a range can have an end container/offset that comes befor开发者_Go百科e its start container/offset. The Mozilla docs on Range.setStart() indicate that this isn't allowed. Is this a Mozilla quirk, or common behaviour?
No, the end of a Range
cannot come before the start. This is common to all browsers that support Range and is implicit in the DOM specification.
However, selection objects can be "backwards". You can check this using the anchorNode
, anchorOffset
, focusNode
and focusOffset
properties of selections (except, of course, in IE).
精彩评论