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

Bryan Dobberstein
Bryan Dobberstein
16,361 Points

A Different Take On Add Item In Appending Nodes | JavaScript and the DOM

I have a bad habit of working ahead while listening to the videos and came up with the following alternative before he explained the addChild function.

addItemButton.addEventListener("click", () => {
                        ul.innerHTML += "<li>" + addItemInput.value + "</li>";
                        addItemInput.value = '';
});
Bryan Dobberstein
Bryan Dobberstein
16,361 Points

I wouldn't say mine is better or worse. Just the result of playing about with what I know so far.

1 Answer

Gabbie Metheny
Gabbie Metheny
33,778 Points

I don't recall that video well enough to say which method is better (though offhand yours looks fine!), but working ahead of the videos is not a bad habit! Keep doing it, it's one of the best ways to learn! ?