Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Sorry I don't understand why Guil use 'previousElementSibling' to store the nested div , please help .

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link href="https://fonts.googleapis.com/css?family=Courgette" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Lato:400,700" rel="stylesheet">
    <title>Traversing the DOM</title>
    <link rel="stylesheet" href="css/style.css">
  </head>
  <body>
    <div class="wrapper">
      <h1>Color Palette:</h1>
      <div></div>
      <ul class="list">
        <li>
          <span>Robin's Egg Blue</span>
          #04c5e6
        </li>
        <li>
          <span>Geyser</span>
          #b7c7d0
        </li>
        <li>
          <span>Jaffa</span>
          #f36f49
        </li>
        <li>
          <span>Shamrock</span>
          #57d6ab
        </li>
      </ul>
    </div>
    <script src="js/scripts.js"></script>
  </body>
</html>
// 5: Store the nested div in a variable named `banner`
const banner = list.previousElementSibling;

banner.className = 'banner';

1 Answer

Steven Parker
Steven Parker
231,269 Points

The whole point of traversal is to get references to elements starting with a reference to another element. In this case, you start with the list (ul) element, and get to the div element just before it:

      <div></div>         <!-- this is the "previousElementSibling" of the list -->
      <ul class="list">   <!-- this is the "list" you start with -->

Thank you so much Steven .