Event click

Benchmark created on


Preparation HTML

<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>

Setup

function test(){
	console.log('test');
}

Test runner

Ready to run.

Testing in
TestOps/sec
HTML - onclick
const div = document.createElement('div');
div.setAttribute('onclick', 'test()');
document.body.appendChild(div);
ready
JS - onclick
const div = document.createElement('div');
document.body.appendChild(div);
div.onclick = test;
ready
JS - addEventListener click
const div = document.createElement('div');
document.body.appendChild(div);
div.addEventListener('click', test);
ready
JQuery - click
const div = document.createElement('div');
document.body.appendChild(div);
$(div).click(test);
ready
JQuery - on click
const div = document.createElement('div');
document.body.appendChild(div);
$(div).on('click', test);
ready

Revisions

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