jQuery.data() vs getAttribute() (v17)

Revision 17 of this benchmark created on


Description

Test the data attribute

Preparation HTML

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js">
</script>
<div data-searchable="true" data-custom1="value1" data-custom2="value2" id="test">
  foo
</div>
<script>
  $el = jQuery(document.getElementById("test"));
  el = document.getElementById("test");
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.data()
$el.data("searchable");
$el.data("custom1");
$el.data("custom2");
ready
getAttribute()
el.getAttribute("data-searchable");
el.getAttribute("data-custom1");
el.getAttribute("data-custom2");
ready
jQuery.attr()
$el.attr("data-searchable");
$el.attr("data-custom1");
$el.attr("data-custom2");
ready
jQuery.prop()
$el.prop("data-searchable");
$el.prop("data-custom1");
$el.prop("data-custom2");
ready
jQuery.data() w/ properties
var data = $el.data();
data.searchable;
data.custom1;
data.custom2;
ready

Revisions

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