Dom操作-元素属性访问

Benchmark created on


Preparation HTML

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <div id="content" >
    <div id="text1">Hello World</div>
    <div id="text2">Hello JavaScript</div>
  </div>
</body>
</html>

Setup

const content = document.getElementById('content')
content.dataset.test = 'benchMarkTest'

Test runner

Ready to run.

Testing in
TestOps/sec
dataset访问
const attribute = content.dataset.test
ready
getAttribute方法访问
const attribute = content.getAttribute('data-test')
ready

Revisions

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