I have a basic question in JS. want to get the inner text of an element that the user clicked on.
I use
document.querySelectorAll(".key")
to get all the elements with the class key, and put event listener on them.
I want to know after the user click on one of them the inner html, and I get
TypeError: elements.addEventListener is not a function
I know this is basic but I am not understand what is wrong. this is my script
<script>
var elements = document.querySelectorAll(".key");
elements.addEventListener("click", function(e) {
console.log(e.target.innerText);
})
</script>