Ad

Inserting A Videotag Inside A Dynamically Created Div

- 1 answer

I am a beginer to javascript.I want to create a div dynamically,and then i want to set a video tag inside that div.After that write this div inside of the body,the another need is that the all elements inside that body should not be visible.The only visible item must be that video. Below code is my try.But it shows the p tag element when video play. Please help me.. Thank you..

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
function dyna()
{

var dynaDiv = document.createElement("div");

dynaDiv.style.background = "red";
dynaDiv.style.color = "white";
dynaDiv.innerHTML = "<video autoplay><source type='video/mp4' src='video/BigBuck_converted.mp4'/></video>";
document.body.appendChild(dynaDiv);
}
</script>
</head>

<body onload="dyna();">
<p>demo</p>

</body>
</html>
Ad

Answer

Got the answer.i just added the bellow code

document.body.innerHTML="";

after

dynaDiv.innerHTML = "<video autoplay><source type='videos/mp4' src='videos/Wildlife.mp4'/></video>";

its worked properly as my need.. thanks alot.. :)

Ad
source: stackoverflow.com
Ad