Im trying out javascript and wanting to add a click event listener to a h1. very simple, click on h1 and it changes colour. it currently works, but when i click anywhere on the page. i only want it to change colour when the h1 is clicked. Any ideas, and keeping close as possible to my code. and only vanilla javascript. thanks
<h1 id="button">HI</h1>
<script>
document.addEventListener("click", (event)=>{
const button = document.getElementById("button")
button.classList.add("red")
});
</script>
<style>
#red{
color:red;
}
</style>