Cannot read property 'addEventListener' of null

The Solution to Cannot read property 'addEventListener' of null is


I think the easiest approach would be to just check that el is not null before adding an event listener:

var el = document.getElementById('overlayBtn');
if(el){
  el.addEventListener('click', swapper, false);
}

~ Answered on 2014-09-29 19:14:37


Most Viewed Questions: