How to set the caret (cursor) position in a contenteditable element (div)?

I have this simple HTML as an example: <div id=”editable” contenteditable=”true”> text text text<br> text text text<br> text text text<br> </div> <button id=”button”>focus</button> I want simple thing – when I click the button, I want to place caret(cursor) into specific place in the editable div. From searching over the web, I have this JS attached … Read more