Test name | Executions per second |
---|---|
.each loop and single on-assignement | 233.5 Ops/sec |
no loop and .on-assignement on list | 1012.6 Ops/sec |
assign event for each item | 230.0 Ops/sec |
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<style>
#container { visibility: hidden; }
</style>
<div id="container">
</div>
var container = $('#container')
var itemCount = 500;
for (var i = 0; i < itemCount; i++) {
container.append('<div>Item ' + i + '</div>');
}
var items = container.children();
items.each(function(index,item) {
var $item = $(item);
$item.on('click', function() { console.log('Item clicked'); });
});
items.on('click', function() { console.log('Item clicked'); });
items.click(function() { console.log('Item clicked'); });