.data() vs .attr() vs $.data()

Benchmark created by Fergal on


Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>

<div id="test" data-foo="abcd"></div>

<script>

window.$div = $("#test");

</script>

Test runner

Ready to run.

Testing in
TestOps/sec
.data()
window.$div.data("foo");
ready
.attr()
window.$div.attr("data-foo");
ready
$.data()
$.data(window.$div, "foo")
ready

Revisions

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

  • Revision 1: published by Fergal on