运行 ❯
获取您
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h2>JavaScript HTML DOM</h2> <div id="main"> <p>Finding HTML Elements by Tag Name</p> <p>This example demonstrates the <b>getElementsByTagName</b> method.</p> </div> <p id="demo"></p> <script> const x = document.getElementById("main"); const y = x.getElementsByTagName("p"); document.getElementById("demo").innerHTML = 'The first paragraph (index 0) inside "main" is: ' + y[0].innerHTML; </script> </body> </html>