<p class="child"> div 元素中 class="child" 的 p </p>
<p class="child"> div 元素中 class="child" 的另外一个 p </p>
<p>在 div 中的 p 元素插入 <span class="child">class="child" 的 span 元素</span> 。</p>
<p>点击按钮为 id="myDIV" 的 div 元素中所有 class="child" 元素添加背景颜色。 the div element with id="myDIV".</p>
<button onclick="myFunction()">点我</button>
<p><strong>注意:</strong> Internet Explorer 8 及更早 IE 版本不支持 getElementsByClassName() 方法。</p>
var x = document.getElementById("myDIV");
var y = x.getElementsByClassName("child");
for (i = 0; i < y.length; i++) {
y[i].style.backgroundColor = "red";