.bind() vs .live() vs .delegate() vs .on() (v5)

Revision 5 of this benchmark created by Rochas on


Description

The Difference Between jQuery’s .bind(), .live(), and .delegate()

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<script>
  function handler() {
    $('p').text("CLICK !");
  }
</script>
<div id="context">
<div>
<p>Event test</p>
</div>
</div>

Test runner

Ready to run.

Testing in
TestOps/sec
.bind
$('p').bind('click', handler);
ready
.live() in document
$('p').live('click', handler);
ready
.live() in a
$('p', $(document)[0]).live('click', handler);
ready
.delegate
$(document).delegate('p', 'click', handler);
ready
.on
$(document).on('click', 'p', handler);
ready
.bind() in context
$('p', $('#context')).bind('click', handler);
ready
.live() in context
$('p', $('#context')).live('click', handler);
ready
.delegate() in context
$('#context').delegate('p', 'click', handler);
ready
.on() in context
$('#context').on('click', 'p', handler);
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.