Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  <ul>
    <li>Item</li>
  </ul>
</body>
</html>
 
var li = document.querySelector('li');
li.addEventListener('click', function(event) {
  debugger;
}, true);
// Listen for normal click events on
// the <li> and dispatch custom event
li.addEventListener('click', function(event) {
  var customEvent = new CustomEvent('mySpecialEvent', {
    bubbles: true,
    detail: { data: 'foo' }
  });
  
  event.currentTarget.dispatchEvent(customEvent);
});
// As we have stated that the custom event
// should bubble, we can listen for the 
// it further up the DOM on the document.
document.addEventListener('mySpecialEvent', function(event) {
  alert(event.detail.data);
});
Output 300px

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

Dismiss x
public
Bin info
wilsonpagepro
0viewers