Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Remove Video <div> - onended

    Hello there,
    I am new to javascript. I would like to remove the div containing a video, by javascript, on the 'onended' event, but am not sure how to do this yet.
    Here is my code so far:
    Code:
    <body onload="javascript:showDiv()">
    <div class="fullscreen" id="fullscreen">
    <video autoplay="autoplay" >
      		<source src="stage.mp4" type="video/mp4" />
    	  	<source src="stage.webm" type="video/webm" />
    	</video>
      </div>
    
    <script> 
    function hideDiv() { 
    if (document.getElementById) { 
    document.getElementById('fullscreen').style.visibility = 'hidden'; 
    } 
    } 
    function showDiv() { 
    if (document.getElementById) { 
    document.getElementById('fullscreen').style.visibility = 'visible'; 
    } 
    } 
    </script> 
       <script>
       
        var video = document.getElementsByTagName('video')[0];
        video.onended = function(e) {
        	hideDiv();
        	document.write("<font color=\"white\">Work???</font>");
        }
    </script>
    I expected the text 'Work???' to be executed after the onended function carries out. However the video is not removed...
    Thanks in anticipation to your answers..
    Zugz

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,396
    Thanks
    12
    Thanked 569 Times in 562 Posts
    Generally you cannot use document.write() to alter elements on your current document. After page load it will always(!) create a new document and overwrite the existing one, including the Javascript code that called it.

    Alternatives: element.innerHTML, document.createElement('TAGNAME'), parent.appendChild(element), parent.insertBefore(element, otherelement), document.createTextNode("This is a text node")


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •