Blogger Information
Blog 35
fans 0
comment 0
visits 16768
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
实例演示二个获取元素的api 2. 实例演示dom常用的遍历方法
手机用户311660634
Original
277 people have browsed it
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>1. 实例演示二个获取元素的api 2. 实例演示dom常用的遍历方法</title>
  8. </head>
  9. <body>
  10. <ul class="test">
  11. <li>test1</li>
  12. <li>test2</li>
  13. <li>test3</li>
  14. <li>test4</li>
  15. <li>test5</li>
  16. </ul>
  17. <script>
  18. // 拿到ol下面的所有元素
  19. const test1 = document.querySelectorAll('.test > *')
  20. // 拿到第一个li元素test1
  21. test2 = document.querySelector('test > *')
  22. let first = test.firstElementChild
  23. first.style.color = 'red'
  24. // 遍历
  25. ;[...test.children].forEach(items => (items.style.border = '1px solid red'))
  26. </script>
  27. </body>
  28. </html>
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post