Skip to content

Instantly share code, notes, and snippets.

@kaid
Created April 23, 2015 09:27
Show Gist options
  • Save kaid/d190c0d0f85b04bb0f0b to your computer and use it in GitHub Desktop.
Save kaid/d190c0d0f85b04bb0f0b to your computer and use it in GitHub Desktop.
move cursor to beginning of element
function moveCursorTo(el) {
let selection = getSelection()
, range = document.createRange();
range.setStart(el.childNodes[0], 0);
range.collapse(true);
selection.removeAllRanges();
selection.addRange(range);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment