I took this example below the book "Eloquent JavaScript" 2nd edition in Portuguese pg.184.
The goal is to draw points on the screen using clicks: every time the mouse is clicked, a blue dot is created where the mouse is pointing.
But beyond the beige style that is applied to the background, nothing else happens. I have already reviewed for syntax errors and can not find anything ... I tried declaring the style in the head, and it also did not change anything.
Follow the code:
<!DOCTYPE html>
<html>
<body>
<!-- Estilo do body, e da classe .dot-->
<style>
body {
height:200px;
background:beige;
}
.dot{
height:8px; width:8px;
border-radius: 4px;
background: blue;
position:absolute;
}
</style>
<!-- Para obter informações precisas sobre o local onde aconteceu um evento do mouse você pode olhar para as
suas propriedades pageX e pageY , que contêm as coordenadas do evento(em pixels) em relação ao canto
superior esquerdo do documento. -->
<script>
addEventListener("click", function(event){
var dot = document.createElement("div");
dot.className("dot");
dot.style.left = (event.pageX -4) + "px";
dot.style.top = (event.pageY -4) + "px";
document.body.appendChild(dot);
});
</script>
</body>
</html>