jquery this vs this directly

Benchmark created by Rob Larsen on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<a id="foo" href="http://www.google.com"></a>
<a id="bar" href="http://www.google.com"></a>
<a id="baz"></a>

Setup

function thisthis() {
      document.getElementById("baz").href = this.href;
    }
    
    function jQueryThis() {
      $("#baz").attr("href", $(this).attr("href"));
    }
    $("#foo").click(thisthis);
    $("#bar").click(jQueryThis);

Test runner

Ready to run.

Testing in
TestOps/sec
use this
$("#foo").trigger("click");
ready
use jquery
$("#bar").trigger("click");
ready

Revisions

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

  • Revision 1: published by Rob Larsen on