Skip to content Skip to sidebar Skip to footer

Difficulty Setting Focus On Newly Created Object In Javascript

So, related to an earlier question, but forgive me for my naive javascript ways. Basically I now want to automatically bring a text input into focus when it is added to the DOM. Pa

Solution 1:

Try the following:

Live Demo

var searchOrig = document.getElementById("search-wrapper"); 

var searchWrapper = document.createElement("div");
searchWrapper.id = "search-wrapper";
searchWrapper.setAttribute('tabindex', '0'); 

searchOrig.parentElement.replaceChild(searchWrapper, searchOrig);
document.getElementById("search-wrapper").focus();

Post a Comment for "Difficulty Setting Focus On Newly Created Object In Javascript"