html - Dynamic video element - JavaScript -


i'm trying establish familiarity dynamic elements in javascript. have put basic example, autoplay small video (stretched fill screen per attached css file).

the css file:

html, body{     margin:0;     height:100%;     overflow:hidden; } img {     min-height:100%;     min-width:100%;     height:auto;     width:auto;     position:absolute;     top:-50%; bottom:-50%;     left:-50%; right:-50%;     margin:auto; } video {     min-height:100%;     min-width:100%;     height:auto;     width:auto;     position:absolute;     top:-50%; bottom:-50%;     left:-50%; right:-50%;     margin:auto; } 

an html file:

<!doctype html> <html> <head>     <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" />     <video autoplay id="videoplayer" src=video.mp4></video> </head> </html> 

this works planned. when page opened, 'video.mp4' stretched fit browser window , play automatically. same process works if replace video element image element; image stretched fit window , displayed on page being opened.

however, want able create both image , video elements dynamically. i.e. user input can change element video (stretched fit browser window) , image (stretched fit browser window). attempt create , display either video or image through process results in blank (white) screen.

my attempt:

<!doctype html> <html> <head>     <link rel="stylesheet" type="text/css" href="css/style.css" media="screen" /> </head> <body> <script type="text/javascript'>     var dynamicvideo = document.createelement("video");     dynamicvideo.autoplay = true;     dynamicvideo.src = 'video.mp4';     document.head.appendchild(dynamicvideo); </script> </body> 

i've inspected page within chrome, , video element has been appended head required. missing here?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -