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 trialsohaib ahmad
2,877 PointsSelect the unordered list element and store it in the variable myList stuck in this challenge please help.
Select the unordered list element and store it in the variable myList ...need help in this question
<!DOCTYPE html>
<html>
<head>
<title>DOM Manipulation</title>
</head>
<link rel="stylesheet" href="style.css" />
<body>
<ul>
<li id="first">First Item</li>
<li id="second">Second Item</li>
<li id="third">Third Item</li>
</ul>
<script src="app.js"></script>
</body>
</html>
let myList =document.getElementsByTagName('li').length;
let firstListItem;
7 Answers
Brian Foley
8,440 Pointslet myList = document.getElementsByTagName('ul')[0];
Steven Parker
231,248 PointsIt looks like you're selecting the wrong item.
Task 1 asks you to "Select the unordered list element and store it in the variable myList". An unordered list would have a tag of "ul
".
Also, you won't need the length property, but if you select an item using getElementsByTagName you will need to add a subscript (using []'s and an index) to convert the collection it returns into a single item. As an alternative you could also select it using querySelector, which returns only the first matching item.
Sebastian Velandia
24,676 PointsSelect the unordered list element and store it in the variable myList is : myList = document.querySelector("ul");
firas fares
Courses Plus Student 2,073 Pointslet myList ; myList =document.querySelector("ul");
Liang Huang
5,178 Pointslet myList = document.getElementsByTagName('ul')[0]; let firstListItem = document.querySelector('li:first-child');
Greg Schudel
4,090 PointsI am confused about the how and where techniques for using methods...
1.) When should you use quotations within a method to call an element? For example, I've seen this and was told it's okay
ul.removeChild(li);
but clearly the above is fine:
myList = document.querySelector("ul");
2.) When should you use double quotations versus single quotations for these methods?
3.) Does anyone have any reference that shows you when you should use one method over another? After using them all they seem despairingly similar. For example, couldn't you use
let myList = getElementByTagName('ul');
for the above question. But what about
let myList = document.querySelectorAll('ul').[0];
Is this a subjective question? If so, I apologize. I never know if what I ask is subjective until I ask! LOL
Rafael silva
23,877 Pointslet myList = document.querySelector('ul'); let firstListItem = document.querySelector('#first');
Mauricio Hernandez
7,208 PointsMauricio Hernandez
7,208 PointsThank you, God bless you and your family.