JSFiddle - React, Tailwind, and code Playground
HTML
<a href="#" id="insert">Insert Input</a>
<a href="#" id="focus">Focus</a>
JavaScript
// Declare Variables
var input = document.createElement('input'),
insertButton = document.getElementById('insert'),
focusButton = document.getElementById('focus');
// Apply the input attributes
input.setAttribute('id', 'test');
input.setAttribute('type', 'text');
// When #insert is clicked
insertButton.onclick = function(){
alert("click");
document.body.appendChild(input);
};
// When #focus is clicked
focusButton.onclick = function(){
document.getElementById('test').focus();
};