I'm new to Javascript and I'm triyng to perform an onClick event on an image in a external .js file using the html tag
<script type="text/javascript" src="embed.js">
The code inside "embed.js" is the following
var image1=new Image();
image1.src="img.gif"
document.write('<IMG src='+image1.src+'>');
$(document).ready( function()
{
$(image1).click( function()
{
alert("Hello World");
});
});
As you can see, I'd like to show an alert when somebody click on the image, but the code I've posted doesn't work. Could you help me? Thanks! :)
@JD it the html code is
<html>
<head>
<title></title>
</head>
<body>
<script src="embed.js"></script>
</body>
</html>
= new Image()is your problem here.. it should be a selector.. $('#image1') maybe? post your html./document.write().document.writeis bad practice. Reasons.