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!

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 JavaScript and the DOM (Retiring) Getting a Handle on the DOM Practice Selecting Elements

Ian Olson
Ian Olson
2,204 Points

Not sure if I'm pulling things right from the HTML

Not sure if I have to Id or or create tags for the html items or if I'm just using the wrong method of pulling items from the html, since I'm just trying to pull the three items from the nav category.

let navigationLinks = document.querySelectorAll( 'nav' );
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>
          <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>

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,243 Points

Hi Ian,

If you're familiar with CSS Selectors, selecting elements with querySelectorAll works the same way. You pass in a string that represents a selector that looks for the elements in the document Tree.

So you want the three list items. We know there's one nav element, so we can target the list items li which is inside the unordered list ulwhich is inside the nav elementnav`

('nav ul li')
Ian Olson
Ian Olson
2,204 Points

Thanks you for the quick reply, it seems like every time I put the 'li' element into the string it says too many elements selected and when I use 'ul' it either gives me that it has selected 0 elements.

let navigationLinks = document.querySelectorAll('nav ul li');

this one says the wrong elements shave been selected.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,243 Points

There’s one more element to add go the selector.

nav ul li a

I didn’t account for the anchor tags inside the list items :-)