我的代码是
<div id="hello">
<div>A</div></div>
<script>
$(function(){
$(document).mousedown(function(event){alert(event.target.id);});
});</script>
现在,当我单击div id“hello”时,它会警告null,因为它采用了中心div的ID,但是我想要外部div的ID。如何实现?
最佳答案
因为目标是最里面的div
try this instead:
event.target.parentNode.id