I have contentEditable element (can be p, div, ...) and I would like to get caret (cursor) position in it. I can normally achieve it with this piece of code: var position = window.getSelection().getRangeAt(0).startOffset; This works fine while the element contains just text. But when the element contains some HTML formatting, the returned position is relative to caret position within included HTML