執行 ❯
建立您
自己的
網站
×
更改方向
儲存程式碼
更改主題,暗/亮
前往 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>