addEventListener only firing once

dom-events, javascript

Solution

You are reassigning `innerHTML` of the whole document:

document.body.innerHTML += response;

on the link `click`. That wipes out all existing DOM elements with their events and creates new DOM structure with no `click`s assigned.

Problem

I'm adding a click event to all links that match a particular selector as part of a JS module I'm creating. It looks something like this. ``` var Lightbox = (function () { var showLightbox = function () { // this does stuff }; var init = function () { var links = document.querySelectorAll(options.selector); for(var i = 0; i < links.length; i++) { links[i].addEventListener('click', function() { showLightbox(); }, false); } }; return { init: init }; })(); Lightbox.init(); ``` On first load the any links on the page that match the selector work. There is also a `closeLightbox()` method that works fine. However when clicking the links for a second time nothing happens. I get no console errors – nothing. Is there something I'm doing wrong when adding the event listener? EDIT: I've updated the code to remove some redundant methods and have pasted the full code here: http://pastebin.com/mC8pSAV2

Original source