This focus method will do this. If you have a link to a newly created item with a name elem, just call:
elem.focus();
Please note that you will need to do this after adding the element to the document at the appropriate point, of course.
source
share