I'm having trouble getting an HTML5 tag using jQuery. Here is my code:
HTML code:
<video id="vid" height="400" width="550"> <source src="movie.mp4" type="video/mp4"> <source src="movie.ogv" type="video/ogg"> </video>
Javascript Code:
function playVid(){ console.log($('#vid')); console.log($('#vid')[0]); $('#vid')[0].currentTime=5; $('#vid')[0].play() } $(document).ready(){ playVid(); }
The code breaks into a .currentTime line with the following error:
InvalidStateError: An attempt was made to use an object that is not, or is no longer, usable
Here is a bit that I canโt compute - the first console.log shows an object that I would expect, inside this object is another object named 0 , and it contains all the properties and methods of the HTML5 video that you expect, including .currentTime .
However, as soon as I make the second log $('#vid')[0] , it shows the HTML code for the video tag, and not the object that I got after calling 0 . I get accurate results for console.log($('#vid')["0"]) and console.log($('#vid').get(0)) .
Is there a way to get object 0 in the object returned by $('#vid') that works in jQuery?
jquery html5 html5-video
Jimmery Jun 27 2018-12-12T00: 00Z
source share