Пытаюсь передвинуть квадрат по нажатию кнопки "Вправо". Но выдаёт ошибку:
Uncaught TypeError: Cannot read properties of undefined (reading 'left')
at HTMLDocument. (script.js:15:32)
(anonymous) @ script.js:15
<span class="circle"></span>
body {
margin: 0px;
padding: 0px;
}
.circle {
display: inline-block;
width: 100px;
height: 100px;
border-radius: 50%;
background-color: black;
left: 0;
margin: 0px;
}
let circle = document.getElementsByClassName('circle');
document.addEventListener('keydown', function (event) {
if (event.code == 'ArrowRight') {
console.log(circle.style.left);
}
});