运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The lastChild Property</h2> <div id="myDIV"> <p>Second child in div</p> <p>Fourth child in div</p> </div> <p>The node name of "myDIV"s last child node is.</p> <p id="demo"></p> <p>Whitespaces inside elements are considered text nodes. In this example, the first, third and fifth child of "myDIV" is a #text node.</p> <script> let text = document.getElementById("myDIV").lastChild.nodeName; document.getElementById("demo").innerHTML = text; </script> </body> </html>