开发者

Making an image, inside a clickable div, unresponsive to the action

开发者 https://www.devze.com 2023-03-29 08:13 出处:网络
So currently I have a image inside a div in such a way: <div onclick=\"doSomething()\"> <img onclick=\"doSomethingElse()\" src=\"image.png\"/>

So currently I have a image inside a div in such a way:

<div onclick="doSomething()">

   <img onclick="doSomethingElse()" src="image.png"/>

</div>

But clicking on the image calls both doSomething() and doSom开发者_如何学CethingElse(). I'd only like it to doSomethingElse().

I "need" to have the containing div "doSomething()" so getting rid of that is not an option.

Any ideas?


Inside of doSomethingElse(), call event.stopPropagation().

var doSomethingElse = function(event) {
   event.stopPropagation();
   // ...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消