<html>
<style>
.democlass {color:red}
</style>
<body>
<h1>HTML DOM Attributes</h1>
<h2>setNamedItem() 方法</h2>
<p>将第一个 H1 的 class 属性设置为 "democlass"。</p>
<script>
const nodeMap = document.getElementsByTagName("H1")[0].attributes;
const node = document.createAttribute("class");
node.value = "democlass";
nodeMap.setNamedItem(node);
</script>
</body>
</html>