<input id="elA" value="element A"> <div id="elB">element B</div> <script> (function () { elA.focus(); elB.onclick = function () { elA.focus(); }; }()); </script>