Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
  article, aside, figure, footer, header, hgroup, 
  menu, nav, section { display: block; }
</style>
</head>
<body>
  <p>demo showing that undelegate doesnt clean up properly</p>
  
  <textarea id="debug" rows="10" cols="50"></textarea>
  <table></table>
</body>
</html>
 
var $table = $('table'),
    $ta = $('#debug');
function dbg(s) { 
    $ta.val($ta.val() + s+'\n');
}
function run() { 
    $table.undelegate();
    // uncommenting the following line seems to make things behave as 
    // expected
    //$table.unbind();
    var html = [];
    for( var x=0; x!=10; x++ ) { 
        html.push('<tr><td><a class="clickme">hello</a></td></tr>');
    }
    $table.html(html.join(''));
    $table.delegate('a.clickme', 'click', function() {  });
    // this should log 1 each time as i have undelegated ... but it doesnt  
    dbg("$table.data().events.click.length = "+$table.data().events.click.length);
}
for( var y=0; y!= 10; y++ ) {
    run();
}
Output

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

Dismiss x
public
Bin info
anonymouspro
0viewers