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

JavaScript performance comparison

Revision 2 of this test case created by

Preparation code

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

Preparation code output

<script> function handler() { $('p').text("CLICK !"); } </script> <p>Event</p>

Test runner

Warning! For accurate results, please disable Firebug before running the tests. (Why?)

Java applet disabled.

Testing in CCBot 2.0.0 / Other 0.0.0
Test Ops/sec
.bind
$('p').bind('click', handler);
pending…
.live() in document
$('p').live('click', handler);
pending…
.live() in a
$('p', $(document)[0]).live('click', handler);
pending…
.delegate
$(document).delegate('p', 'click', handler);
pending…
.on
$(document).on('click', 'p', handler);
pending…

Compare results of other browsers

Revisions

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

1 Comment

Broutard commented :

Expected results ! "on" is binded on document, while for others, we must first find all "p" elements.

Event