English
The event is only triggered in the parent node but not in the child node.
Pay attention to the difference between event.srcElement : e.target in browsers such as IE and Firefox
Click to run the following code:
Run the demo <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http ://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title> Only at parent level Events triggered in div are not triggered in child divs</title> <style type="text/css"> div{background:#eee;margin:20px auto;border:1px solid #ccc;} div div{background:# fff;margin:40px;} #ctnr{width:500px;} #hd{height:300px;} #bd{height:200px;} </style> </head> <body> <div id="ctnr"> ctnr This div container contains two divs, <br />but the action is not allowed to occur in the child div it contains, and is only triggered in the parent div. <div id="hd">hd is not triggered here</div> <div id="bd">bd is not triggered here</div> The action is only triggered in the blank space</div> <script type=" text/javascript"> <!-- function initDrag(e) { var oDragHandle = document.getElementById&&document.all ? event.srcElement : e.target; if(oDragHandle.id == "ctnr"){alert(oDragHandle.id + " clicked.");} } document.onclick=initDrag; //--> </script> </body> </html>