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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![karan Badhwar](https://secure.gravatar.com/avatar/cc6b8912184a3f8fc42420983065b702?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
karan Badhwar
Web Development Techdegree Graduate 18,135 PointsWhy my code is not working and is it an ok way to write this solution
Hi, I tried to modify the solution it is working only if I don't write
button.textContent = 'Edit'; again why is that and is my solution Ok?
button.addEventListener('click', (e) => {
const span = document.createElement('span');
span.textContent = input.value;
li.insertBefore(span, input);
li.removeChild(input);
button.textContent = 'Edit';
Here is a snapshot as well.
1 Answer
![Bob Swaney](https://uploads.teamtreehouse.com/production/profile-photos/9907902/micro_this_is_me.jpg)
Bob Swaney
13,010 PointsIt looks to my like you are missing another 'else if' clause... i.e. else if (button.textContent === 'Save') {
then all of the stuff that the form data saves along with flipping the button back to 'Edit' }
It looks like its not working as is because you are already in a block that has a click event on the 'ul'. so when the button is clicked and it says 'Edit' it's trying to fire 2 click events due to 'Event Bubbling'. So because the button already says 'Edit', its firing the 'else if' clause which is then triggering another click event on the button that says 'Edit' and keeping the text context as 'Edit'
Hope this clarifies and is even the right answer! Good Luck!