jQuery.data() vs getAttribute() (v16)

Revision 16 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 id="test">
  foo
</div>
<script>
  $el = jQuery(document.getElementById("test"));
  el = document.getElementById("test");
function setData(el, p, s)
{
el[p] = s;
}
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
jQuery.data()
$el.data("searchable", true);
$el.data("searchable");
ready
setAttribute()
el.setAttribute("searchable", true);
el.getAttribute("searchable");
ready
$.data
$.data($el, "searchable", true);
$.data($el, "searchable");
ready
direct & dirty
setData(el, 'searchable', true);
if (el.searchable == false) {
alert('a');
}
ready

Revisions

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