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
Rafal Dziobek
3,771 PointsEventListener
Hello, Could you tell me why this code is not working. Actually it works it changes the content of the li but only for like 000.1 sec and then it gets back to normal.
const input = document.querySelector('#input'); // selects input field
const submit = document.querySelector('#submit'); // selects submit button
let liz = document.querySelector('li');
submit.addEventListener('click', () => {
liz.textContet = 'sadasdasd';
});
1 Answer
Steven Parker
243,228 PointsYou didn't show the HTML part of the code, but I'm guessing you have a form on it, and the default action of a form is to reload the page when you submit.
You can stop this with the "preventDefault" method or by triggering the event with a control that is not also associated with the submit action.