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
Brian Foley
8,440 PointsStuck :(
Challenge Task 1 of 2
On line 2 of app.js, get all the paragraph elements within section and assign them to the paragraphs variable.
I tried answering:
const section = document.querySelector('section'); let paragraphs = document.getElementsByTagName('p');
I figure the correct answer is very easy and I'm going to kick myself. Please help. Thanks!
Brian Foley
8,440 Points4 Answers
Umesh Ravji
42,386 PointsHi Brian, my comment was wrong, as you've probably noticed.
let paragraphs = section.children;
This is just about using an elements children property.
Brian Foley
8,440 PointsThanks very much!
Ming Jun Lim
10,060 PointsIf you do section.children, wouldn't that select other html elements too?
Startup Shell
38,037 PointsHi, for this same question I tried 'section.querySelectorAll('p');' Why wouldn't this work?
NSOFT doo Mostar
1,473 PointsIn this task we had luck that all childrens was paragraphs:
<section> <p>This is the first paragraph</p> <p>This is a slightly longer, second paragraph</p> <p>Shorter, last paragraph</p> </section>
so we might use section.children;
But what if there was not only paragraphs in section tag? how could we fetch only 'p' tag? because getElementsByTagName did not worked...
Andreas Schultze
Courses Plus Student 3,951 Points<code> let paragraphs = section.children; </code> Is the answer but actually this is not correct as this would select all HTML elements not just the paragraphs.
Umesh Ravji
42,386 PointsUmesh Ravji
42,386 PointsWhich challenge is this for? From the question, it's probably just as simple as:
let paragraphs = section.getElementsByTagName('p');Since it's only asking for paragraph tags within the section element, you want to call the getElementsByTagName on the element, and not the entire document.