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 trialmalcolm mowlam
3,856 Pointsquiz question 5 of 5
how do you use documents.getElementsByTagName
2 Answers
Brandon White
Full Stack JavaScript Techdegree Graduate 34,662 PointsHi malcolm mowlam,
document.getElementsByTagName is a method that returns a collection of elements. For instance, if you were to write something like:
const paragraphs = document.getElementsByTagName('p');
// the above would store a collection of paragraph elements in paragraphs i.e. [p1, p2, p3, p4...]
To then be able to manipulate one of the paragraph elements, you would use indexing. So say you wanted to manipulate the second paragraph in the paragraphs collection (and as such, the second paragraph in the html document), to select it you would write the following: paragraphs[1]
.
Does that help?
malcolm mowlam
3,856 PointsThank you Brandon helps a great deal