JSFiddle - React, Tailwind, and code Playground
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<button>Add lots of elements and events</button>
<button> Remove all elements and events</button>
JavaScript
// Add a bunch of divs with click events.
$('button').first().click(function() {
for (var i = 0; i < 1000; ++i) {
$('<div>').appendTo('body').click(function() {
// Nothing.
});
}
});
// Clean up all divs with .off() and Node.removeChild().
$('button').last().click(function() {
$('div').each(function() {
$(this).off();
this.parentNode.removeChild(this);
});
});