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");

Test runner

Ready to run.

Testing in
TestOps/sec
通过style修改元素样式
content.style.backgroundColor = "red";
ready
通过attribute修改元素样式
let style = content.getAttribute("style") || '';
style += "background-color: red;";
content.setAttribute("style", style); 
ready

Revisions

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