I am creating a video player with dashjs. I seem to get the error "Uncaught ReferenceError: Invalid left-hand side in assignment on element attribute" when I try to add a data attribute to my function for creating the <video>
element inside my video-container element.
function createVideoElement() {
videoElement = document.createElement("video");
videoElement.id = "video";
videoContainer = document.getElementById("video-container");
videoElement.autoplay = false;
videoElement.src = "";
videoElement.controls = true;
videoElement.data-video-id = window.datavideoId;
videoContainer.appendChild(videoElement);
window.addEventListener('popstate', onBackNav);
return videoElement;
}
The error occurs at:-
videoElement.data-video-id = window.datavideoId;
Ok, so it doesn't like my "data-video-id". If I remove the data-video-id line, the <video>
element is created with the appropriate attributes. How else can I do this without getting this error?