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 trialCedric Hoppe
3,908 PointsIs this an acceptable alternative solution?
i used this solution a few videos ago, would this be acceptable or is it bad code / bad practice?
addItemButton.addEventListener("click", () => {
let ul = document.getElementsByTagName("ul")[0];
let li = document.createElement("li");
li.innerHTML = addItemInput.value + "<button class='moveUp'>Move Item Up</button><button class='moveDown'>Move Item Down</button><button class='remove'>Remove Item</button>";
ul.appendChild(li);
addItemInput.value = "";
});
I'm just adding the buttons with the innerHTML function.
1 Answer
Steven Parker
231,271 PointsThis is an expedient practical solution, as I expect you discovered from testing.
But I think the point of the exercise was to give you an opportunity to practice using some of the other DOM manipulation funcitons and element properties.