<html class="reftest-wait"> <body onload="start()"> <div onfocus="done()" contenteditable>foo<div contenteditable="false"><a href="#">bar</a></div>baz</div> <script> var div = document.querySelector("div"); function start() { div.focus(); } function done() { var sel = getSelection(); // Set the caret right before "baz" sel.collapse(div.lastChild, 0); document.documentElement.removeAttribute("class"); } </script> </body> </html>