<div> <a href="#" id="element1">Show Text</a> <button id="element2">Show Text</button> </div> <h1 id="myH1"></h1>
div{ display: inline-flex; flex-direction: column; gap: 20px; }
var element1 = document.getElementById("element1"); var element2 = document.getElementById("element2"); [element1, element2].forEach(function(myElements){ myElements.addEventListener("click", function(){ document.getElementById("myH1").innerHTML = "Hello World!"; }); });
HTML
CSS
JS