this.startOffset
and this.endOffset
in the following code are values I'm using to select individual characters within nodes:
this.startOffset = this.node.length - 1 ||
this.node.firstChild.length - 1 ||
this.node.childNodes.item(0).length - 1 ||
this.node.childNodes.item(0).firstChild.length - 1
this.endOffset = this.node.length ||
this.node.firstChild.length ||
this.node.childNodes.item(0).firstChild.length
I'm using -1
in this.startOffset
because that's the value at the beginning of a character. (e.g. 0,1
will select the first character in the node.)
However, because this.node.childNodes.item(0).length - 1
will become 0 in the first character, it will return false
instead of 0
and the code will reach this.node.childNodes.item(0).firstChild.length - 1
, causing an error.
How can I make it so that 0
doesn't return false, and instead sets this.startOffset
to 0
?