0

I added a listener to an unordered list to perform a function when a text area element within the ul was changed. When the text area is changed, I wanted to get the value of the now changed text area, and save it. When I try to save the value in newNotes, I am given back the INITIAL value of the text area, not the value after the text area has been changed. Isn't that the whole point of the listener, to be triggered upon a change?

ul.addEventListener('change',(e)=> { 
if(e.target.tagName === "TEXTAREA") { // if the ul was changed and a textarea was targeted
    const li = e.target.parentNode; // the parent list item of the text area
    const liName = li.firstChild.textContent; // this is a string
    var newNotes = e.target.textContent; // PROBLEM : RETURNS WRONG VALUE
    console.log(newNotes);
    updateNotesTo(liName, newNotes); // regarding localStorage         

}              
});
0

2 Answers 2

1

You want the value from textarea

Change

var newNotes = e.target.textContent; 

To

var newNotes = e.target.value; 
Sign up to request clarification or add additional context in comments.

Comments

0

You have to use the .value attribute.

var newNotes = e.target.value;

See also, Textarea.textcontent is not changing

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.