example09.html 680 B

1234567891011121314151617181920212223242526272829
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title></title>
  6. </head>
  7. <body>
  8. <div id="page">
  9. <h1 id="header">List</h1>
  10. <h2>Buy groceries</h2>
  11. <ul>
  12. <li id="one" class="hot"><em>fresh</em>&nbsp;<em>figs</em></li>
  13. <li id="two" class="hot">pine nuts</li>
  14. <li id="three" class="hot">honey</li>
  15. <li id="four">balsamic vinegar</li>
  16. </ul>
  17. <script src="js/list.js"></script>
  18. </div>
  19. <script>
  20. var elems = document.querySelectorAll('#page .hot');
  21. for (var i = 0; i < elems.length; i += 1) {
  22. alert(elems[i].textContent);
  23. }
  24. var em = document.querySelector('#one>em');
  25. alert(em.textContent);
  26. </script>
  27. </body>
  28. </html>