I have a problem with this code, when I click the button it should do the function "hello" and open an alert but it doesn't work.
function hello(){
alert("hi");
}
document.getElementById("one").onclick = hello();
<button id="one">Click me </button>
I know that I could simply do like this
button onclick="hello()";but I need it to work with the javascript version. Basically my question is: Is there a way to open the function "hello" when I click the button without putting the onclick in the button tag??