JSFiddle - React, Tailwind, and code Playground
HTML
<div id="placeholder">
</div>
JavaScript
function randomString(length) {
var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz'.split('');
if (! length) {
length = Math.floor(Math.random() * chars.length);
}
var str = '';
for (var i = 0; i < length; i++) {
str += chars[Math.floor(Math.random() * chars.length)];
}
return str;
}
var ph = document.getElementById('placeholder');
var rndId = randomString(8);
var div = document.createElement('div');
div.id = rndId;
div.innerHTML = "This div has the id:" + rndId;
ph.appendChild(div);