Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,654 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.