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 trialSteve Moore
6,793 PointsFor the mental exercise...
Hello - Playing around with the code to see what works and what doesn't led me to a couple questions. I am looking for an explanation as to why the code below doesn't clear the text in the list item immediately after populating it as well as clearing the input.value since it is also assigned to the text variable. Not to suggest this is desirable behavior of course. Just curious. Thank you.
form.addEventListener('submit', (e) => {
e.preventDefault();
let text = input.value;
const ul = document.querySelector('#invitedList');
const li = document.createElement('li');
li.textContent = text;
ul.appendChild(li);
text = "";
});
1 Answer
Shane Oliver
19,977 PointsBecause text and li.textContent are not the same. Text and Li have different memory addresses. You can see that as they are both stored in different variables respectively
Steve Moore
6,793 PointsSteve Moore
6,793 PointsThank you Shane.