I'm new to Javascript and just trying to understand the language better. I was having some trouble using the onclick function and figure out how to make it work - however I'm hoping someone could explain to me why my code in line 2 doesn't work (i've tried "reveal;" "reveal();" and "reveal(this);" ) but line 3 works.
https://plnkr.co/edit/8YlEDwABSvvGDBcotFSE
var clickButton = document.getElementById("button");
clickButton.onclick = reveal(this); // this code doesn't work
//clickButton.setAttribute("onClick", "reveal(this)"); // but this one does
function reveal(obj) {
this.obj = obj;
obj.innerHTML = "X";
}
Thank you and much appreciate everyone's input.