Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7821039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:31:10+00:00 2026-06-02T07:31:10+00:00

I have an embedded youtube video iframe in my html that I need to

  • 0

I have an embedded youtube video iframe in my html that I need to stop programatically, but I am unable to set the id of the iframe. Therefore I am trying to create the youtube object by passing the DOM element to the YT.Player constructor rather than the iframe id, as specified in the docs. I have also appended ‘?enablejsapi=1’ to the end of my iframe src url.

I have loaded the youtube js api at the top of my js file using the following code:

var tag = document.createElement('script');
tag.src = "http://www.youtube.com/player_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
function onYouTubePlayerAPIReady(){ console.log('yt api ready'); }

After that I have the following code:

$(function(){
    $('a.close').click(function(){
        var player = new YT.Player($('iframe').get(0));
        player.stopVideo();
    });
})

I get the output:

yt api ready
Uncaught TypeError: Object [object Object] has no method 'stopVideo'

I’m assuming I’m screwing up the object instantiation somehow, but I don’t know how to do this correctly. How do I create a YT.Player object without passing the constructor the iframe id? Thanks for any help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T07:31:12+00:00Added an answer on June 2, 2026 at 7:31 am

    I needed to move the stop video call into the player object’s ready event. The following changes fixed it for me

    Added the following function:

    function onMyPlayerReady(event) { event.target.stopVideo(); }
    

    And changed the yt.player constructor to:

    new YT.Player($('iframe').get(0), { events: { 'onReady': onMyPlayerReady } });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a page with multiple YouTube embedded players that I need to listen
We have a Wicket app with a page that includes an embedded Youtube video.
I have a webpage where I've embedded a youtube video. I need to add
I have a YouTube video embedded on my site using an iFrame . I
I have an embedded YouTube video on my site that plays in a lightbox.
I want to have an embedded chromeless youtube video preload its video WITHOUT playing
I have an absolutely placed div with an embedded YouTube video inside of it.
I have embedded a youtube video into a website via a drupal module (I'm
I have a slider which includes 4 youtube videos that are embedded via the
I've embedded a Youtube video in my facebook app, but when I scroll down,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.