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 trialIsaac Hughes
3,711 PointsI do not know what is happening with the code, it is not working
I looked over the code and checked it a bunch of times but i cannot get it to work the error i get in the console is "SCRIPT438: SCRIPT438: Object doesn't support property or method 'addEventListener' "
const toggleList= document.getElementById('toggleList');
const listDiv= document.getElementsByClassName('list');
const input=document.querySelector('input');
const p=document.querySelector('p.description');
listDiv.addEventListener('mouseover',(event) =>{
if(event.target.tagName =='LI') {
event.target.textContent = event.target.textContent.toUpperCase();
}
});
listDiv.addEventListener('mouseout',(event) => {
if(event.target.tagName =='LI'){
event.target.textContent = event.target.textContent.toLowerCase();
}
});
1 Answer
KRIS NIKOLAISEN
54,972 PointsI made the following change:
const listDiv= document.getElementsByClassName('list')[0]
note the index at the end. getElementsByClassName retrieves a collection of elements so the code above references the first item.
Isaac Hughes
3,711 PointsIsaac Hughes
3,711 Pointscan't believe I missed that, it works now thanks :)