Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
  <style>
    #blue {
      background-color: blue;
      width: 100px;
      height: 100px;
    }
    #grey {
      background-color: grey;
      width: 100px;
      height: 100px;
    }
    #green {
      background-color: green;
      width: 50px;
      height: 50px;
    }
  </style>
<body>
  1. Mouse down on green box and observe the events. </br> 2. Realese the mouse and obsever the events.</br>
  <div id="grey"> <div id="green"></div></div>
  <div id="blue"> </div>
  <div id="log"> </div>
  
  <script>
    var eventList = ['pointerdown', 'mousedown', 'pointermove', 'mousemove', 'pointerup', 'mouseup'];
    ['grey', 'green', 'blue'].forEach(function(id) {
      var div = document.getElementById(id);  
      eventList.forEach(function(eventName) {
        div.addEventListener(eventName, function(event) {
          document.getElementById('log').innerHTML += id  + " " + event.type + ' ' + event.target.id + " <br>" ;
          if (event.type == "pointerdown" && event.target == div) {
            document.getElementById('blue').appendChild(div);
            div.parentNode.removeChild(div);
          }
        });
        
      });
    });
    
  </script>
</body>
</html>
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x