I am creating an empty div in javascript DOM. but when I call on it some function, for example,
var hover = document.createElement("div"); hover.className = "hover"; overlay.appendChild(hover); hover.onClick = alert("hi");
the onClick function does not work. Instead, it displays a warning as soon as it reaches the div script creation part. What am I doing wrong?
source share