The .focus() method .focus() not work for the Input.(id="renameaction") Element Input.(id="renameaction") .
Called when the button is clicked (div id="win_rename") .
This element (id="renameaction") disappears and appears using display:none/display:block .
After appearing (renameshow is being accessed) it should appear and user input should be focused on this element.
browser chrome, os win 7.
It works only for the first time - at startup, I assume, because of the presence of the autofocus attribute, if the element is hidden and shown again, then there will be no focusing on it.
How to solve and what is wrong?
<div id="win_rename" value='' onmousedown='renameshow()'>Переименовать</div> ... <input type='text' autofocus style='display:none;border #000 solid 1px;' id="renameaction" onkeypress="if (event.keyCode == 13) rename();" value="null" > ... function renameshow(){ disableactions(); var rel = document.getElementById("renameaction"); rel.style.zIndex = '5000'; rel.style.display = 'block'; rel.style.position = 'absolute'; var el = document.getElementById("contentelementselected"); if (!el) var el = document.getElementById("contentfolderselected"); rel.style.width = parseInt(winquery[0].wincontent.style.width)-44; rel.value = el.innerHTML; winaction.elementid = el; rel.style.height=19; el.appendChild(rel); rel.focus(); } function disableactions(){ var back = document.getElementById("win_back"); var open = document.getElementById("win_open"); var openInExplorer = document.getElementById("win_openInExplorer"); var copy = document.getElementById("win_copy"); var paste = document.getElementById("win_paste"); var filedelete = document.getElementById("win_delete"); var rename = document.getElementById("win_rename"); back.style.display='block'; open.style.display='none'; openInExplorer.style.display='none'; rename.style.display='none'; filedelete.style.display='none'; copy.style.display='none'; if (copyobj=='null') paste.style.display='none'; else paste.style.display='block'; var addfav = document.getElementById("win_addfav"); addfav.style.display='none'; winaction.addfav.style.display='none'; } Full code: https://dl.dropboxusercontent.com/u/44864159/www.rar