By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,480 Members | 771 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,480 IT Pros & Developers. It's quick & easy.

am pasting a suggested code on Javascript but getting a response Undefined. kindly he

P: 6
Expand|Select|Wrap|Line Numbers
  1. document.body.addEventListener('click', function () {
  2.      var myParent = document.getElementById("Banner"); 
  3.      var myImage = document.createElement("img");
  4.      myImage.src = 'https://thecatapi.com/api/images/get?format=src&type=gif';
  5.      myParent.appendChild(myImage);
  6.      myImage.style.marginLeft = "160px";
  7. });
Jan 3 '19 #1

✓ answered by gits

you would need to explain more what the exact problem is - basically i think the only thing that can go wrong here seems to be that you dont have an element with the id 'Banner' in your page - so that code cant find the element to append the image to.

Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,298
you would need to explain more what the exact problem is - basically i think the only thing that can go wrong here seems to be that you dont have an element with the id 'Banner' in your page - so that code cant find the element to append the image to.
Jan 4 '19 #2

P: 6
Thank you but it turned out to be fine.Warm Regards.
Jan 6 '19 #3

Post your reply

Sign in to post your reply or Sign up for a free account.