Hi, I’m trying to learn AJAX, so I used
https://jsonplaceholder.typicode.com to create a program that fetches data and displays it, I also added a button that displays comments for each post, and the code works for the first few posts, for the later posts (30 onwards), I get the following error:
Uncaught TypeError: Cannot set property ‘innerHTML’ of undefined
now sometimes, I don’t know how, but the code will work for later posts, but sometimes it doesn’t, it’s quite confusing, I’ve used console.log to see if the comments are retrieved, and they are always logged into the console on clicking the button, for some, it’s just not inserted in DOM . I’d appreciate any help in this, thanks!
Here’s the code: https://codepen.io/goprime/pen/YJgLPM