jQuery by id vs Document.getElementById
Comparing speed of getting element by id with jQuery vs Vanilla JS
Date tested:
one year ago
User agent:
Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:107.0) Gecko/20100101 Firefox/107.0
Test name
Executions per second
jQuery
2959611.0 Ops/sec
Vanilla JS
3001142.0 Ops/sec
Benchmark definition (click to collapse):
HTML Preparation code:
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.1.0.min.js"></script> <div id="testElement"></div>
Tests:
jQuery
var el = $("#testElement")[0]; var className = el.className;
Vanilla JS
var el = document.getElementById('testElement'); var className = el.className;
Open this result on MeasureThat.net