开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜