Yogesh Gadade
Yogesh Gadade

Reputation: 49

Can I use onclick() event inside image tag?

I am trying to call the function by this way, but onclick() is not working in the below code.

<img id="myImg" src="uploads/15051139151863de8020740a7899d26ead30d24770.jpg" onclick="modalview()" width="300" height="200">

Upvotes: 2

Views: 16478

Answers (1)

Jax-p
Jax-p

Reputation: 8551

Correct syntax:

<img src="http://example.com" onclick="function()">

Or you can use extern call like this:

$("img").click(function() {
  alert("Image clicked");
});

Upvotes: 2

Related Questions