I'm trying to make a simple Javascript function to open a window with a bigger image when an image is clicked on. What happens is this test alert pops up on the page load and then does nothing when i click on the image. Here is the code
function zoom()
{
alert("test!");
}
document.getElementById("us").onclick=zoom();
Try this
function zoom()
{
alert("test!");
}
document.getElementById("us").onclick=zoom;
function zoom()
{
alert("test!");
}
document.getElementById("us").onclick=function(){zoom(variable1)};
If you need to pass a variable.
for es6 onclick = () => zoom(i)
works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With