JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<h1 class="words">
Hello!
</h1>
<button class="btn" type="button">Click Me!</button>
</body>
CSS
body {
margin: 0;
padding: 0;
background-color: white;
}
.words {
position: relative;
color: black;
font-size: 20px;
left: 0;
top: 0;
}
JavaScript
{
$(".btn").click(function () {
var bodyWidth = document.body.clientWidth;
var bodyHeight = document.body.clientHeight;
var randPosX = Math.floor(Math.random() * bodyWidth);
var randPosY = Math.floor(Math.random() * bodyHeight);
$(".words").css("left", randPosX);
$(".words").css("top", randPosY);
});
}
{
$(document).ready(function () {
$(".btn").click(function () {
$(".words").clone().appendTo("body");
});
});
}