app HTMLCollection(HTML的集合),不是数组 类数组对象,可以使用数组的属性,可以for循环

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <title>Document</title>
    7. </head>
    8. <body>
    9. <div class="app">
    10. hello world
    11. </div>
    12. <div class="text">
    13. go
    14. </div>
    15. <script>
    16. // 如何获取DOM元素
    17. var app = document.getElementsByTagName("div");
    18. // app HTMLCollection(HTML的集合),不是数组 类数组对象,可以使用数组的属性,可以for循环
    19. console.log(Array.isArray(app))
    20. console.log(app.length)
    21. for(var i=0;i<app.length;i++){
    22. console.log(app[i])
    23. }
    24. </script>
    25. </body>
    26. </html>