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 trialManav Rattan
19,139 PointsOn line 2 of app.js, select all links in the unordered list with the id of "gallery" and assign them to galleryLinks.
let galleryLinks = document.querySelectorAll('#gallery li');
let navigationLinks = document.querySelectorAll('nav a');
let galleryLinks = document.querySelectorAll('#gallery li');
let footerImages;
//#navigation .navigationLevel2 li
<!DOCTYPE html>
<html>
<head>
<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">
</head>
<body>
<header>
<a href="index.html" id="logo">
<h1>Nick Pettit</h1>
<h2>Designer</h2>
</a>
<nav>
<ul>
<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>
</ul>
</nav>
</header>
<div id="wrapper">
<section>
<ul id="gallery">
<li>
<a href="img/numbers-01.jpg">
<img src="img/numbers-01.jpg" alt="">
<p>Experimentation with color and texture.</p>
</a>
</li>
<li>
<a href="img/numbers-02.jpg">
<img src="img/numbers-02.jpg" alt="">
<p>Playing with blending modes in Photoshop.</p>
</a>
</li>
</ul>
</section>
<footer>
<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>© 2016 Nick Pettit.</p>
</footer>
</div>
<script src="js/app.js"></script>
</body>
</html>
8 Answers
andren
28,558 PointsYou are selecting the li (list-item) elements, the task wants you to select the a (anchor) elements. Like this:
let galleryLinks = document.querySelectorAll('#gallery a');
michaelkyllo
11,330 PointsWhy doesn't
let galleryLinks = document.querySelectorAll('#gallery li a');
work? the quiz told me it selected 3 links instead of 2?
Seth Kroger
56,413 PointsSee above.
Mauricio Hernandez
7,208 PointsThank you and have a blessed day.
Seth Kroger
56,413 Pointsli's are list items, but a's are links. So you should select "#gallery a" as opposed to "#gallery li"
Mars Epaecap
5,110 PointsWhy doesn't
let galleryLinks = document.querySelectorAll('#gallery ul a');
work?
Seth Kroger
56,413 PointsThe <ul>
here is <ul id="gallery">
; #gallery already selects the ul. There is no other <ul>
within it so '#gallery ul' won't match anything.
Jenn Glas
9,475 PointsI don't understand why (or didn't realize) you can select multiple things within in the parentheses. I thought it was one of two things e.g. ( 'li') or ('[title = label']). Can someone explain this? Thanks!
andren
28,558 PointsJenn Glas: The thing you put into the parenthesis of the querySelector
/querySelectorAll
method is a CSS selector. Anything that would count as a valid selector in CSS is accepted by those methods. And there are a lot of different CSS selectors that can be used.
I would recommend you take a look at this article. The article lists the most common and useful CSS selectors that exists. While I disagree with the article's headline suggesting that you have to memorize all of them, I would recommend you at least bookmark that article or something for later reference and study. CSS selectors are very powerful and very useful in JavaScript.
Both of the examples in your post are CSS selectors 'li'
is a tag selector and '[title = label']
is an attribute selector. The CSS selector that allows you to select nested elements that was shown in the answers above is a descendant selector.
Kedrick Martin
8,243 PointsThe correct answer is let galleryLinks = document.querySelectorAll('section a ');
Murat Can Berber
3,238 Pointslet galleryLinks = document.querySelectorAll("#gallery a");
charles phiri
13,268 Pointsthis works let galleryLinks = document.querySelectorAll("#gallery li a");
Jermaine Witter
33,087 Pointslet galleryLinks = document.querySelectorAll('.social-icon'); This also works because each of the images in the footer have a class of social-icon.
Michael Rooze
6,636 PointsIs the hashtag there because its an ID?
Maren Lilleberre
17,531 Pointsyes:)
Mauricio Hernandez
7,208 PointsMauricio Hernandez
7,208 PointsHave a blessed day.