Data attr vs. class or id targeting

Benchmark created by Joe on


Description

Is targeting a dom element with data attribute slower?

Preparation HTML

<button class="btn" id="submit-button" data-js="submit-button">Submit</button>

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

Test runner

Ready to run.

Testing in
TestOps/sec
By Class
$(".btn").hide();
ready
By ID
$("#submit-button").hide();
ready
By Attribute - using * all
$("*[data-js='submit-button']").hide();
ready
By Attribute - qualifying element
$("button[data-js='submit-button']").hide();
ready

Revisions

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

  • Revision 1: published by Joe on