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

Revision 3 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>

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.