I'm having trouble writing some JavaScript for a project. I have the HTML code:
<html>
<head>
<title>Mouse Tail and Spawn</title>
<script src="tail.js"></script>
</head>
<body>
<div id="tail" style="position:absolute; display:none">
Click to spawn an egg.
</div>
</body>
</html>
I want to write the JavaScript to have the text in the div to follow the mouse cursor and also for it to spawn an 'o' when and where the mouse is clicked.
I'm wanting to use the DOM methods createElement
and appendChild
to do so but can't envisage in my head how to do it, at this stage I have no JavaScript written. Does anyone have any links to tutorials on this or have any tips to help.
This is actually fairly straight-forward. We need only to listen for clicks on the root element, inspect the click event object for click coordinates, and set up some basic styling of an ad-hoc element: