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 Moving to an Editing State

Myles Young
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Myles Young
Full Stack JavaScript Techdegree Graduate 22,056 Points

I got it (with some help) check my comments for how It is done, and what is doing what!

else if(button.textContent === 'save'){ // making code for saving changes. return to what it was before edit const input = li.firstElementChild; //reference node const save = document.createElement('span'); //created new node save.textContent = input.value; //setting the save spans text content to = the input the user types li.insertBefore(save, input); li.removeChild(input); //to replace old span with new span button.textContent = 'edit'; }

1 Answer

Myles, your code is a bit hard to read in that format, but it appears you did more or less the same thing I did! The only difference is instead of creating a constant named save, I named mine span, just like it was in the block for "edit." In my opinion it keeps things consistent and easier to understand, especially since in this context "save" is also the text content of the button.

    } 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';
    }