<button id="btn"></button>
button:
1:
var btn = document.getElementById("btn");
btn.onclick = function(){
alert("HelloWorld");
}
2:
function hello() {
alert("addEventListener()");
}
var btn = document.getElementById("btn");
btn.addEventListener("click", hello, false);
when these two methods add click events to button objects, why does one use onclick
and the other uses click
?