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 8276469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T08:23:03+00:00 2026-06-08T08:23:03+00:00

I am working with embeded youtube video. I need to replace it with the

  • 0

I am working with embeded youtube video. I need to replace it with the image and when the image is clicked the video starts playing which I have implemented:

<script type="text/javascript">
   function start_video() {
      var iframe = '<iframe title="YouTube video player" width="590" height="360" src="http://www.youtube.com/embed/nCgQDjiotG0?autoplay=1&amp;rel=0&showinfo=0" frameborder="0" title="none" allowfullscreen></iframe>';
      document.getElementById("video_player").innerHTML = iframe;
   }
</script>

And html:

<div id="video_player"><img style="cursor: pointer;" onclick="start_video();" src="fake_image.jpg" alt="Play Video" /></div>

But now I have a problem stopping this video by clicking on some div or some other element and replacing video back with image at the same time.

  • 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-08T08:23:05+00:00Added an answer on June 8, 2026 at 8:23 am

    Why don’t you just give the iframe an id and then remove the iframe and place the image there?

    function stop_video() {
        var elem = document.getElementById('video_iframe');
        var parent = elem.parentNode;
        parent.removeChild(elem);
        var image = document.createElement('img');
        image.setAttribute('src','yourImage.jpg');
        parent.appendChild(image);
    }
    

    I also suggest that you do not set the innerHTML as you did, you should actually deal with objects like this one above.

    function start_video() {
        var iframe = document.createElement('iframe');
        iframe.setAttribute('title','Youtube video player');
        iframe.setAttribute('width','590');
        iframe.setAttribute('height','360');
        iframe.setAttribute('src','http://www.youtube.com/embed/nCgQDjiotG0?autoplay=1&amp;rel=0&showinfo=0');
        iframe.setAttribute('frameborder','0');
        iframe.setAttribute('allowfullscreen','allowfullscreen');
        document.getElementById('video_player').appendChild(iframe);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am playing an embeded youtube video with the play() function. This is all
LoadHtmlString UIWebView is not working. I want to play embeded you tube video. I
I need your advice. We have an already working web resource management application, we
I'm working in an embedded Linux environment and I have some Python code which
I'm working on a webapp where I need store references to YouTube videos in
I have the following code, necessary to track an embedded Youtube video in my
I am currently working on a project where in which I need to package
I am trying to obtain embeded code through extracting variables from Youtube video URLs.
I am working with a website where I will have several embedded YouTube videos.
I'm working on an embedded systems which provides an interface with certain types. The

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.