1var myElem = document.getElementByID('ElemID');
2myElem.onclick = function() {
3 //do stuff
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>