this.id vs this.getAttribute("id")

Benchmark created by Niels on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="test"></div>
<a href="testurl" id="a"></a>

Setup

var me = document.getElementById("test");
    var $me = $(me);
    var a = document.getElementById("a");
    var $a = $(a);

Test runner

Ready to run.

Testing in
TestOps/sec
this.id
me.id
ready
this.getAttribute("id")
me.getAttribute("id")
ready
jQuery.attr()
$me.attr("id")
ready
this.href
a.href
ready
this.getAttribure("href")
a.getAttribute("href")
ready
jQuery.attr("href")
$a.attr("href");
ready

Revisions

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

  • Revision 1: published by Niels on