<button onclick="myFunction()">Click me</button>
function myFunction() {
document.getElementById("demo").innerHTML = "Hello World";
}
<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>
<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>