The problem is that you're trying to set the range's boundaries in the first child node of the <div>
element, which is either a white space-only text node if your HTML really does look like it does in the question, or the <span>
element if there is no white space in your actual HTML. In the latter case, i.e. setting a range boundary in an element, the offset represents the number of child nodes of the element preceding the boundary.