YouTube Example(APIs)

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.

Hey there @owolagbadavid,

Thank you for digging into this. Could you point me to a running version of your code? Also, if you believe there is an error in the MDN Web Docs page you linked to, please let us know by filing an issue using the “Report a problem…” link at the bottom of the page. Thank you.

–
Schalk
Staff Community Manager - MDN Web Docs

2 Likes

This is it live
And there is no error in the MDN Web Docs page just the source code for the YouTube API example