Handle html body double click event with ondblclick and get clicked element - Javascript DOM Event

Javascript examples for DOM Event:onclick

Description

Handle html body double click event with ondblclick and get clicked element

Demo Code

ResultView the demo in separate window

<!doctype html>
<html>
   <head> 
      <meta charset="utf-8"> 
      <title>ondblclick event example</title> 
      <script>
    function initElement() {/*w  w  w.j a  v a2  s. c  o m*/
        var body = document.getElementById("bdy");
        body.ondblclick = showAlert;
    }
    function showAlert(e){
        console.log(e.target.id);
    }
    window.onload = initElement;

      </script> 
   </head> 
   <body id="bdy"> 
      <div id="id1">
         dasd
      </div> 
      <div id="id2">
         dasda
      </div>  
   </body>
</html>

Related Tutorials