Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript JavaScript and the DOM Making Changes to the DOM Get and Set Content with textContent and innerHTML

Michael Davis
Michael Davis
6,334 Points

My .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

Try changing headlin.textContent to headline.textContent

Michael Davis
Michael Davis
6,334 Points

That 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
gregperry3
5,737 Points

Same 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.