JSFiddle - React, Tailwind, and code Playground
HTML
<button id="inject">Inject</button>
JavaScript
$(document).ready(function() {
$('#inject').on('click', function(e) {
$('body').html('<form id="login" action="./login"> \
<label for="username">Username:</label> \
<input type="text" name="username" id="username" /> \
<label for="password">Password:</label> \
<input type="password" name="password" id="password" /> \
<input type="submit" value="Login" /> \
</form>');
});
$('#login').on('submit', function(e) {
e.preventDefault();
// Some validation and as test if event is fired
alert("Fired!");
});
});