JSFiddle - React, Tailwind, and code Playground

HTML

<div id ="main"></div>

JavaScript

//create a div
var divElem = $('<div class="divText"></div>');

var elemid = 'mytext0.15942923246580176'; //Replace this with '123' and it will work correctly

//create input element inside it
var inhtml = "<input type='text' id='" + elemid + "' value='hello' />";

//add to page
$(divElem).html(inhtml).appendTo('#main');

//retrieve input element
alert(document.getElementById(elemid).value);    //WORKS!
alert($('#' + elemid).val()); //undefined. DOES NOT WORK