Im working on a video selection using JS, and I came across this answer which helped me out. The problem is
- The answer is nearly 7 years old
- Im only able to test on chrome, but I get an error saying
Uncaught TypeError: video.appendChild is not a function
This is the snippet of js/html of where the error is coming from.
var video = document.getElementsByClassName("player");
var source = document.createElement("source");
source.setAttribute("src", "../shows/2020.mp4");
video.appendChild(source);
video.play();
$(document).on("change", "vid-select", function() {
var show = $("option:selected", this).data("show")
source.setAttribute("src", "../shows/" + show + ".mp4")
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="past-player">
<select class="vid-select" data-target= ".past-player .player">
<option data-show: "2020">2020</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
</select>
<video class="player"></video>
</div>
I just want to know what is going wrong with the video
var and why it cant have a child added to it to show the video.
I had originally tried getElementById
with the <video id="player">
on the first line of js, but this returned null
.
EDIT: I have also tried querySelector
and still recieved null