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 trial

JavaScript Object-Oriented JavaScript (2015) Constructor Functions and Prototypes Making the UI Work

Timothy McMahan
Timothy McMahan
8,481 Points

Hi Everyone, I keep getting the error Uncaught TypeError: Cannot set property of 'innerHTML' of null any suggestions?

I have gone through the code several times but I can't figure this one out.

Uncaught TypeError: Cannot set property of 'innerHTML' of null
Playlist.prototype.renderInElement = function(list) {
list.innerHTML = '';
  for(i=0; i < this.songs.length; i++){
  list.innerHTML += this.songs[i].toHTML();
  }
};

2 Answers

Seth Kroger
Seth Kroger
56,413 Points

Since the only thing innerHTML is referenced from is the function's argument, list, the problem is happening when or before you call renderInElement. Instead of passing it a list element, you're passing it nothing. Either you're looking up an element that doesn't exist or some other error occured when looking that element up (like the id not matching up).

Nothing is being passed to the function when it's being called. Go to app.js and check your playlist.renderInElement(playlistElement) line. See 3:33 in the video.