1.firstElementChild 只读属性,返回指定父元素的第一个子元素,若没有子元素,则为 null。
2.lastElementChild 只读属性,返回指定父元素的最后一个子元素,若没有子元素,则为 null。
3.nextElementSibling 只读属性,返回指定父元素的下一个兄弟元素,若没有,则为 null。
4.previousElementSibling 只读属性,返回指定父元素的前一个兄弟元素,若没有,则为 null。
<p>1111</p> <p>2222</p> <ul> <li>AAA</li> <li>BBB</li> <li>CCC</li> <li>DDD</li> <li>EEE</li> </ul> <p>3333</p> <p>4444</p> <script type="text/javascript"> let oUl=document.getElementsByTagName("ul")[0]; oUl.firstElementChild.style.background="blue"; oUl.lastElementChild.style.background="green"; oUl.nextElementSibling.style.background="orange"; oUl.previousElementSibling.style.background="pink"; </script>