Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<title>Foo</title>
<div>Expected value: <b>Handled</b></div>
<script>
    var delegate = function(a,b,c,d,e,f){f=a[b="on"+b];a[b]=function(g){if(g.target.matches(d))c.call(g.target,g,e);f?f(g):0}}
    // Create event handler to set "Actual value".
    delegate(document, "click", function() { // Delegate the event to the document.
        this.innerHTML = "Handled";          // Set html of element that triggers the event.
    }, "b#ret");                             // Looking for bold tags with id "ret".
</script>
<!-- Add the element after delegation to show that event handling is delegated properly. -->
<div>Actual value: <b id="ret"></b></div>
<script>
    // Trigger event.
    document.getElementById("ret").dispatchEvent(new Event("click", {bubbles: true}));
</script>
Output

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

Dismiss x
public
Bin info
Alexei-Bpro
0viewers