javascript - Uncaught ReferenceError: Invalid left-hand side in assignment on element attribute -
this question has answer here:
i creating video player dashjs. seem error "uncaught referenceerror: invalid left-hand side in assignment on element attribute" when try add data attribute function creating <video>
element inside 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, doesn't "data-video-id". if remove data-video-id line, <video>
element created appropriate attributes. how else can without getting error?
you can not use -
part of variable name, because interpreted minus (subtraction) operator.
to fix this, can try videoelement['data-video-id'] = window.datavideoid;
or better videoelement.setattribute('data-video-id', window.datavideoid);
Comments
Post a Comment