Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

162
Views
How to destroy video

I have never used player.destroy(); before in code so I am unsure of how to add it.

How should it be written into the code?

I am using it to destroy the iframe for the video, when the X button is clicked.

After a svg play button is clicked, there is an X button that you press which when pressed, destroys the video.

Are either of these the right way?

Click Run, not update to test code:

Like this: https://jsitor.com/RTH542DH1o

function createResetHandler(player) {
    const resetVideos = document.querySelectorAll('.exit');
    resetVideos.forEach(function resetVideoHandler(video) {
      video.addEventListener('click', function resetVideoHandler() {
        if (!player) {
        } else {
          player.stopVideo();
          player.destroy();
          player = null; 
        }
      });
    });
  }

or like this: https://jsitor.com/xaLXppyXJ5

 function createResetHandler(player) {
    const resetVideos = document.querySelectorAll('.exit');
    resetVideos.forEach(function resetVideoHandler(video) {
      video.addEventListener('click', function resetVideoHandler() {

        player.destroy();

      });
    });
  }

or would it be written a different way?

https://developers.google.com/youtube/iframe_api_reference

Removes the <iframe> containing the player.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!