运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,暗/亮
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>The Element Object</h1> <h2>The firstElementChild Property</h2> <div id="myDIV"> <p>A P element - First child in "myDIV"</p> <span>A Span element - Last child in "myDIV"</span> </div> <p>The tag name of the first child element in "myDIV" is:</p> <p id="demo"></p> <script> let name = document.getElementById("myDIV").firstElementChild.tagName; document.getElementById("demo").innerHTML = name; </script> </body> </html>