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 trialAlta Angela
5,993 PointsWhich line here set the className of each li to 'responded' if their checkbox is checked?
filterCheckbox.addEventListener('change',(e)=>{
const isChecked = e.target.checked;
const lis = ul.children;
if (isChecked){
for (let x = 0; x<lis.length; x+=1)
{
let li = lis[x];
if (li.className === 'responded'){
li.style.display = '';
}
else{
li.style.display = 'none';
}
}
}else{
for (let x = 0; x<lis.length; x+=1)
{
let li = lis[x];
li.style.display = '';
}
}
});
It is working perfectly fine but I'm curious what made the className of checked items to 'responded'. or is it automatic that the className will be set to 'responded' once checked?
3 Answers
mryoung
4,156 PointsIs this all the Javascript used?
Alta Angela
5,993 Pointsul.addEventListener('change', (e) =>{
console.log(e.target.checked);
const checkbox = event.target;
const checked = checkbox.checked;
const listItem = checkbox.parentNode.parentNode;
if(checked){
listItem.className = 'responded'; //this sets the className to 'responded' if the checkbox is checked.
}
else{listItem.className = '';
}
});
mryoung
4,156 PointsWhat was the line?
Alta Angela
5,993 PointsAlta Angela
5,993 PointsYes mryoung , that's the same code as what Guil used in the video.
Alta Angela
5,993 PointsAlta Angela
5,993 PointsI realized what line it is.. Thanks mryoung for trying to help me with this :)