Custom Data Attributes (data-*) using JavaScript
JavaScript performance comparison
Info
JavaScriptでカスタムデータ属性にアクセスするにはdataset IDLとgetAttribute() / setAttribute()があり、 またjQueryでカスタムデータ属性にアクセスするには、data()を使う方法と、attr()を使う方法の2つあります。
パフォーマンスはどれがよいのでしょうか?
Preparation code
<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<div id="dog" data-dog-breed="poodle">プードルがダルメシアンに変身</div>
Preparation code output
プードルがダルメシアンに変身
Test runner
Warning! For accurate results, please disable Firebug before running the tests. (Why?)
Java applet disabled.
| Test | Ops/sec | |
|---|---|---|
dataset IDL |
|
pending… |
getAttribute() / setAttribute() |
|
pending… |
data() |
|
pending… |
attr() |
|
pending… |
You can edit these tests or add even more tests to this page by appending /edit to the URL.
0 comments