Added DOM event listener before adding the details

Added the listener so the script can be sure that DOM elements are ready to be manipulated.