1var element = document.getElementById("elem");
2element.onclick = function(event) {
3 console.log(event);
4}
1<button onclick="myFunction()">Click me</button>
2
3<p id="demo"></p>
4
5<script>
6function myFunction() {
7 document.getElementById("demo").innerHTML = "Hello World";
8}
9</script>