In the YouTube Example on Third-party APIs section.removeChild(e.target.a);
does not remove the the unplayable YouTube videos, it throws an error in the console.
When I was trying to debug the issue, I created a variable and assigned the last unplayable video to it.
let mike = "";
.
.
//The event handler that grabs the ID of each video, and checks its duration
if (duration === 0) {
console.log(`Video ${myId} cannot be played, so it was deleted.`);
mike = e.target;
section.removeChild(e.target.a) //throws an error
}
I examined the different properties of target "YT.Player"
object i.e "mike"
mike.a
OR (e.target.a)
was undefined.
I discovered mike
had a property mike.i
(refers to the YouTube iframe), so I changed e.target.a to e.target.i and it removed the unplayable videos.