0

I have a JS code that is not currently not executing on Chrome Console. I have tried indenting the code differently.

document.body.addEventListener('click', function () {
  var myParent = document.getElementById("Banner"); 
  var myImage = document.createElement("img");
  myImage.src = 'https://thecatapi.com/api/images/get?format=src&type=gif';
  myParent.appendChild(myImage);
  myImage.style.marginLeft = "160px";
});
Sean Bright
  • 118,630
  • 17
  • 138
  • 146
  • Please elaborate on what it *is* doing. "It isn't working" is not descriptive enough. –  Jul 05 '18 at 14:25
  • 1
    Possible duplicate of [document.body.addEventListener is not working](https://stackoverflow.com/questions/7167969/document-body-addeventlistener-is-not-working) – vahdet Jul 05 '18 at 14:26
  • 1
    It is working for me (minus the fact that appendChild is not working since there is I assume no Banner element) but the event is hooked to the body and triggers. What is your problem with it? – DanteTheSmith Jul 05 '18 at 14:27
  • The code when put into console should execute a gif of a cat playing once you click anywhere on the webpage. However the response I get instead is "Uncaught TypeError: Cannot read property 'appendChild' of null at HTMLBodyElement. (:5:12) (anonymous) @ VM49:5" does appendChild not work – Pegasus Jul 09 '18 at 11:41

0 Answers0