代码示例:(标识:jsck_element_children_4)
<!DOCTYPE html>
<html>
<body>
<h1>Element 对象</h1>

<h2>children 属性</h2>

<p>点击“更改”可更改 body 所有子元素的背景。</p>

<button onclick="myFunction()">更改</button>

<h2>我是 h2 元素</h2>
<div>我是 div 元素</div>
<span>我是 span 元素</span>

<script>
function myFunction() {
const collection = document.body.children;
for (let i = 0; i < collection.length; i++) {
    collection[i].style.backgroundColor = "red";
  }
}
</script>

</body>
</html>
运行结果: