I am looking to create a unique webpage where text appears in various random locations each time the page is loaded. To achieve this, I need to set the left and top distances of a DIV element containing text at random positions on the page. The code snippet provided below gives an overview of my initial idea:
<body>
<script>
function generateRandomCoordinates() {
var leftValue = Math.round(Math.random()*1000);
var topValue = Math.round(Math.random()*1000);
}
window.onload = generateRandomCoordinates;
</script>
<div style="left:leftValue; top:topValue;">
<p>Test</p>
</div>
</body>
How can I apply variables to the CSS style of a DIV element?
If you have any alternative methods for creating a dynamically relocating DIV, please share them as well. Thank you!