Кнопка вызова нажмите на событие в JavaScript

//Solution #1 use onClick Method in html tag
<button onclick="myFunction()">Click me</button>

// in <script>
function myFunction() {
  document.getElementById("demo").innerHTML = "Hello World";
}

//Solution #2 Add addEventListener
<p id="demo">Click me.</p>
<script>
const p = document.getElementById("demo");
p.addEventListener("click", myFunction);
function myFunction() {
  document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>

//Solution #3 use onClick Method in DOM
<p id="demo">Click me.</p>
<script>
const p = document.getElementById("demo");
p.onclick = function() {myFunction()};
function myFunction() {
  document.getElementById("demo").innerHTML = "YOU CLICKED ME!";
}
</script>
Tung