<html>
<head>
<title>Mouse Events Demo</title>
</head>
<body>
<h1>Mouse Events Demo</h1>
<p>Click anywhere inside the box to change its background color.</p>
<div id="game-container">
</div>
</body>
</html>
xxxxxxxxxx
#game-container {
width: 200px;
height: 200px;
border: 1px solid black;
position: relative;
cursor: pointer;
}
xxxxxxxxxx
var gameContainer = document.getElementById('game-container');
gameContainer.addEventListener('click', function () {
var randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
gameContainer.style.backgroundColor = randomColor;
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.