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 DOM Scripting By Example Editing and Filtering Names Saving Names

Help with edit/save button

So when I click the "edit" button it get rids of the checkbox and turns it into the text input . Then when I hit "save" it keeps it in the input box instead of updating it to the list item. I can't find what's wrong with my code. ul.addEventListener('click', (e) => { if (e.target.tagName === 'BUTTON') { const button = e.target; const li = button.parentNode; const ul = li.parentNode; if (button.textContent === 'Remove') { ul.removeChild(li); } else if (button.textContent === 'Edit') { const span = li.firstElementChild; const input = document.createElement('input'); input.type = 'text'; input.value = span.textContent; li.insertBefore(input, span); li.removeChild(span); button.textContent = 'Save'; } else if (button.textContent === 'Save') { const input = li.firstElementChild; const span = document.createElement('span') span.textContent = input.value; li.insertBefore(span, input); li.removeChild(input); button.textContent = 'Edit'; } } });

1 Answer

Steven Parker
Steven Parker
229,783 Points

This bit of code seems OK by itself. But it's hard to understand what "get rids of the checkbox" means since the HTML part of the code isn't shown. A better way to share your environment is to make a snapshot of your workspace and post the link to it here.

And when you do need to post code directly, be sure to use Markdown formatting to preserve the appearance.