Use jQuery to manage your video tag

So, I want to use the jQuery function to collect the URL from the REL link and pass it to the element.

Collecting REL and sending it to it is not a problem ... but what is needed to start the functions of loading and playing elements from jQuery?

Here is what I still have:

$(function(){ $('a.componentLink').click(function() { event.preventDefault(); var vidURL = $(this).attr('rel'); $('#myVideo > source').attr('src', vidURL); $('#myVideo').load(); $('#myVideo').play(); }) }); 

ATM, it does not play ... I believe jQuery does not have access to the playback function ... but there must be a way.

+6
javascript jquery html video
source share
1 answer

You need to call .play() on the element itself, not on jQuery selection. Follow these steps:

 $(function(){ $('a.componentLink').click(function() { event.preventDefault(); var vidURL = $(this).attr('rel'); $('#myVideo').attr('src', vidURL); var video = $('#myVideo').get(0); video.load(); video.play(); }) }); 
+19
source share

All Articles