Jquery 'on' (as former 'live) vs 'on' (bind on element) vs 'on' (bind on parent element)

JavaScript performance comparison

Test case created

Preparation code

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id='list'>
</div>
 
<script>
Benchmark.prototype.setup = function() {
    var list = $("#list");
    var n = 10;
    var elements = new Array();
    for(var i=0; i<n; i++){
       elements.push($('<div>', {class : "test"}));
    }
};
</script>

Preparation code output

Test runner

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

Java applet disabled.

Testing in unknown unknown
Test Ops/sec
'on' as 'bind' on element
for(var i=0; i<n; i++){
   elements[i].on('click', function(){
   });
   list.append(elements[i]);
}
pending…
'on' as live on parent
list.on("click", ".test", function(){
});

for(var i=0; i<n; i++){
   list.append(elements[i]);
}
pending…
'on' as bind on parent
for(var i=0; i<n; i++){
   list.append(elements[i]);
}
list.on("click", function(e){
   var target = e.target,
         $target = $(target);
   if (target.nodeName === 'DIV') {
   }
});
pending…

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

Compare results of other browsers

0 comments

Add a comment