TypeError: 'undefined' is not a function in Safari

I am trying to start a video but getting an error

TypeError: 'undefined' is not a function (evaluating '$("video")[0].play()')

But everything works fine in other browsers

$('a').bind('click', function() {
  $('video')[0].play();
});

<video controls>
  <source id="webm" src="/video.webm" type="video/webm" />
  <source id="mp4" src="/video.mp4" type='video/mp4'/>
</video>
+4
source share
3 answers

I don’t understand why I didn’t answer this question right now, but it says:

The latest version of Safari for Windows is very old (v5 was originally released in 2010) and most likely does not support html5 video, and thus the DOM element that it is looking $('video')[0]at has no function play().

+3
source

playIt is not a jQuery function, but a function of the DOM element. Therefore, you need to call it on the DOM element.

:

 $('video').get(0).play();  

, jQuery - $('#videoId').get(0).play().


:

, .preventDefault(). preventDefault().

$('a').bind('click', function(e) {
   e.preventDefault();
   $('video')[0].play();
});
0

If you use safari in the windows, you must install the QuickTime player . Without it, the video will not play.

0
source

All Articles