Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM (Retiring) Getting a Handle on the DOM Practice Selecting Elements

Selecting indirect descendant elements from the document.

I need help with the below code.

I've looked at MDN, StackOverflow, W3Schools and other resources, understood how to use multiple CSS selectors using querySelectorAll() method. However, it's still not working.

To test around and see if other methods would work, I tried out parentNode notation and other possibilities, but to no avail.

Please help!

let navigationLinks = document.querySelectorAll("nav li");
let galleryLinks;
let footerImages;
<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Nick Pettit | Designer</title>
    <link rel="stylesheet" href="css/normalize.css">
    <link href='http://fonts.googleapis.com/css?family=Changa+One|Open+Sans:400italic,700italic,400,700,800' rel='stylesheet' type='text/css'>
    <link rel="stylesheet" href="css/main.css">
    <link rel="stylesheet" href="css/responsive.css">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <a href="index.html" id="logo">
        <h1>Nick Pettit</h1>
      <nav class="nav">
          <li><a href="index.html" class="selected">Portfolio</a></li>
          <li><a href="about.html">About</a></li>
          <li><a href="contact.html">Contact</a></li>
    <div id="wrapper">
        <ul id="gallery">
            <a href="img/numbers-01.jpg">
              <img src="img/numbers-01.jpg" alt="">
              <p>Experimentation with color and texture.</p>
            <a href="img/numbers-02.jpg">
              <img src="img/numbers-02.jpg" alt="">
              <p>Playing with blending modes in Photoshop.</p>
        <a href="http://twitter.com/nickrp"><img src="img/twitter-wrap.png" alt="Twitter Logo" class="social-icon"></a>
        <a href="http://facebook.com/nickpettit"><img src="img/facebook-wrap.png" alt="Facebook Logo" class="social-icon"></a>
        <p>&copy; 2016 Nick Pettit.</p>
  <script src="js/app.js"></script>

3 Answers

Steven Parker
Steven Parker
215,939 Points

The method is fine, but the instructions ask you to "select all links inside the <nav> element" and this code is selecting list items instead.

Links are implemented with anchor (a) elements.

Hi Steven, I can't imagine why I ended up in this situation where I took 'li' as links. This resolved my issue.

Thanks a lot.

Cheers, Nimish.

Steven Parker
Steven Parker
215,939 Points

You might take comfort in knowing that based on other forum questions, this is actually a common mistake. I guess it's because most tag names have letters in common with the names used to describe them. But mistakes are often the best teachers, so you'll most likely remember this exception now!

Happy coding.

Perhaps that more enlightening than comforting! But in retrospect, I still can't believe I did that. It seems so trivial that it's nearly impossible to miss.

"It's so overt it's covert" - from one of Shelock Holmes movies!

Thanks again.