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 trialMichael Davis
6,992 PointsMy .addEventListener is returning null. I cant figure out why.
Here's the code I copied from the video maybe I looked over something but I get an error in the console saying my .addEventListiner cannot read properties of null.
const btnUpdate = document.querySelector ('.btn-main');
btnUpdate.addEventListener('click', () => {
const headline = document.getElementById ('headline');
const input = document.querySelector ('.input-main');
headlin.textContent = input.value });
2 Answers
jb30
44,807 PointsTry changing headlin.textContent
to headline.textContent
Michael Davis
6,992 PointsThat was definitely a part of it Thank you! The other error I noticed, and maybe it was something I missed in a previous lesson but in the btnUpdate variable they told us to link it to the class ('.btn-main') but when I checked the index the button element didn't have a class attribute so I ended up changing it to the ID attribute ('#btn-main'). I don't know if this was a mistake in the class or if I just missed something but it took me a few min to figure it out,
gregperry3
7,660 PointsSame thing just happened to me. btn-main was the id of that <button> instead of a class. I could have missed that being changed in a previous lesson too.