HTML part
<div class="cont">
<button>1</button>
<button>2</button>
<button>3</button>
<button>4</button>
</div>
<div class="div">1</div>
CSS part
body{
margin:0;
padding:0;
user-select:none;
}
.cont{
display:flex;
justify-content:space-evenly;
align-items:center;
height:100vh;
}
.div{
position:absolute;
top:0;
left:0;
right:0;
bottom:0;
font-size:50px;
}
JS part
console.clear()
const button = document.querySelectorAll('button')
let arr = Array.from(button)
const div = document.querySelector('.div')
arr.forEach((list) => {
list.addEventListener('click',() => {
console.log(div.innerText = list.textContent)
})
})
My thinking is that when I absolute positioned the div,the event stopped working