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

JavaScript Interacting with the DOM Responding to Events Listening for Events with addEventListener()

Samuel Kleos
seal-mask
.a{fill-rule:evenodd;}techdegree
Samuel Kleos
Front End Web Development Techdegree Student 13,728 Points

.getElementsByTagName() vs .querySelectorAll()

In practical terms, if I append an item to a new Nodelist that I want to store somewhere else on the page, what is the benefit of having a live node item, vs a static one?

Ie.

Live Node Item: document.getElementsByTagName('li')[0]

vs

Static Node Item: document.querySelectorAll('li:nth-child(1)')

Also is there a difference if I add event listeners to array items by looping over an HTML Collection vs Static Nodelist?

1 Answer

Travis Alstrand
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Travis Alstrand
Treehouse Teacher

Hey there Samuel Kleos !

I was getting ready to type out a big response but I found these two pages which honestly explain the differences much better than I ever could :smiley:

They're both easy reads and shared more info than I was able to think of as well. I hope these shed new light!

Article on medium.com

Article on softauthor.com