You are calling the makeOscarPlayer()
function before you are creating it.
You need to wrap the makeOscarPlayer()
function declaration in a script tag.
You are passing in document.getElementById("my-video")
as a parameter to makeOscarPlayer()
, but there is no HTML element with an id of 'my-video'. You are giving the function a parameter of null
, while the function declaration has no parameters.
You need to tell the script where to put the new element. To do that, you grab an existing element and use parentNode
and insertBefore
Here is a barebones version that I got working for your reference:
<html>
<head>
<title>
Media Player
</title>
</head>
<script>
</script>
<body>
<div id="my-player">
Hello!
</div>
</body>
</html>
<script type="text/javascript">
function makeOscarPlayer(){
var div = document.createElement("div");
div.innerHTML = `hello`;
// This grabs the element that you want to create a new element by
var existingDiv = document.getElementById("my-player");
// This tells the script where to put the new element
existingDiv.parentNode.insertBefore( div, existingDiv.nextSibling);
}
// Must be called in the same script block or after the script holding the function declaration is loaded
makeOscarPlayer();
</script>
For more information on how parentNode
and insertBefore
work, see this Stack Overflow question