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 trialbabasariffodeen
6,475 Pointsclass is not getting added, and nothing changes when checkbox is checked
const form = document.querySelector('#registrar');
const input = form.querySelector('input');
const ul = document.querySelector('#invitedList');
form.addEventListener('submit', (event) => {
event.preventDefault();
const text = input.value;
input.value = '';
const li = document.createElement('li');
li.textContent = text;
const label = document.createElement('label');
label.textContent = 'Confirmed';
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
label.appendChild(checkbox);
li.appendChild(label);
ul.appendChild(li);
});
ul.addEventListener('change', (event) =>{
const checkbox = event.target;
const checked = checkbox.checked;
const listItem = checkbox.parentNode.parentNode;
if(checked){
listItem.className = 'responded';
}else{
listItem.className = '';
}
});
The code seems not to work for me, when I click on the checkbox nothing happens. Any help would be appreciated.
1 Answer
Jennifer Nordell
Treehouse TeacherHi there, babasariffodeen! I took the code you provided in the question above and put it in the workspace, and it works for me. The class "responded" is assigned according to the dev tools and a sort of teal border appears around the box. I also see no errors in the console.
So here are some things to check:
- It seems silly, but we all forget to save our work sometimes. Make sure your work is saved.
- Once confirmed as saved, refresh the page.
- If this is still not working, your browser may be loading in cached data. Try clearing your browser cache and see if that helps or launch the preview in a private browsing tab.
Hope this helps!
babasariffodeen
6,475 Pointsbabasariffodeen
6,475 PointsThanks Jennifer! I just tried clearing browser cache and it worked! :)