jQuery attr() vs. Native setAttribute() (v28)

Revision 28 of this benchmark created by Akash Kava on


Description

jQuery's attr() method will always have more overhead because of the extensibility added.

Preparation HTML

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script><input type="text" id="btn"></div>

Setup

var btn = document.getElementById('btn');
    var $btn = $(document.getElementById('btn'));

Test runner

Ready to run.

Testing in
TestOps/sec
set attribute directly
btn.disabled="disabled";
ready
Native setAttribute()
btn.setAttribute("disabled", "disabled");
ready
getElementById() with jQuery attr()
$btn.attr("disabled", "disabled");
ready
jQuery selector with Native setAttribute
$btn[0].setAttribute("disabled", "disabled");
ready
Native setAttribute as indexed property
btn["disabled"]="disabled";
ready

Revisions

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