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
Vic Mercier3,276 Points
Steven Parker225,664 Points
You have a few issues here.
Owa makes a good point, but you have some other issues as well:
- you wrote "getElementByTagName" (singular) but the function is actually "getElementsByTagName" (plural)
- you wrote "lenght" instead of "length"
Owa Aquino19,277 Points
Sorry it will not alert 2 as a result. Because it can not find the 'h' because there is no such html element. The best way if you want to count the h1 and h2 element is to select their parent element and count its child element.
Hope this help.
Jeremy Castanza12,080 Points
There's several ways to do what you're trying to do. Another way might be to add a class to each header and select by class using the getElementsByClassName method. As Owa Aquino mentioned though, you can't select "h" by itself.