admin管理员组文章数量:1391991
I have placed a Div on top of an img tag. In my example the Div with cls 'justForClickCls' is placed on top of an img which is wrapped in another div 'gameBoardElementGreyCls'. The mousedown on the 'justForClickCls' div is not firing in IE. However it works in every other browser.
Here is the code. Any help is much appreciated. By the way i'm testing it i IE 9
<div class='gameBoardElementCls'>
<div id='9' class='justForClickCls' style='z-index:10;position:absolute;margin:20px;width:80px;height:80px;'></div>
<div class='gameBoardElementGreyCls'><img src='img/greygmelement.png' width='110px' height='110px'></img></div>
</div>
<script>
$("div.justForClickCls").mousedown(function () {
alert('clicked 1');
});
</script>
I have placed a Div on top of an img tag. In my example the Div with cls 'justForClickCls' is placed on top of an img which is wrapped in another div 'gameBoardElementGreyCls'. The mousedown on the 'justForClickCls' div is not firing in IE. However it works in every other browser.
Here is the code. Any help is much appreciated. By the way i'm testing it i IE 9
<div class='gameBoardElementCls'>
<div id='9' class='justForClickCls' style='z-index:10;position:absolute;margin:20px;width:80px;height:80px;'></div>
<div class='gameBoardElementGreyCls'><img src='img/greygmelement.png' width='110px' height='110px'></img></div>
</div>
<script>
$("div.justForClickCls").mousedown(function () {
alert('clicked 1');
});
</script>
Share Improve this question asked Apr 29, 2012 at 23:50 user983327user983327 9732 gold badges8 silver badges13 bronze badges
3 Answers
Reset to default 4In my case setting opacity to zero is not a valid solution since the div has other elements that would bee invisible. This solved the problem. Add the following to the div style: background-image:url('.');
Got stuck with the same problems for hours and user983327's last ment saved my day: IE required me to set a background color for the element to work.
Setting the opacity to 0 then achieved the same result as having a transparent background and made the whole thing cross browsers patible.
First thing you should fix is the closing tag in the img
<img src='img/greygmelement.png' width='110px' height='110px'></img>
To
<img src='img/greygmelement.png' width='110px' height='110px' />
Next, mousedown seems unnecessary since you are trying to trap the click. Simple use click
instead of mousedown
.
Now check this demo of you coding, which is working
本文标签:
版权声明:本文标题:javascript - Mousedown event not fired on a Div if the Div is placed on top of an img tag - issue is only in IE - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744657636a2618062.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论