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>
</body>
</html>

Setup

function init() {
	document.body.innerHTML = `<div id="content">
  		<div id="text1">Hello World</div>
  		<div id="text2">Hello JavaScript</div>
	</div>`
}
const content = document.getElementById('content')

Test runner

Ready to run.

Testing in
TestOps/sec
dataset方法
init()
content.dataset.test = 'benchMarkTest'

ready
setAttribute方法
init()
content.setAttribute('data-test','benchMarkTest')
ready

Revisions

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