JSFiddle - React, Tailwind, and code Playground
HTML
<button id="erstellen">Erstellen</button>
<div id="element"></div>
JavaScript
$('#erstellen').click(function() {
$("<form>", { id: "form1", class: "" }).appendTo('#element');
$("<input>", { id: "imgInp", type: "file" }).appendTo('#form1');
$("<img>", { id: "image", src: "#" }).appendTo('#element');
});
$('#element').on("change", "#imgInp", function () {
console.log('on')
function readURL(input) {
console.log('hier!')
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function (e) {
$('#image').attr('src', e.target.result);
}
reader.readAsDataURL(input.files[0]);
}
}
$("#imgInp").change(function(){
readURL(this);
});
});