Reputation: 67
I'm trying to grab the src of a dynamic HTML5 video, and append the src as a link below the video so it can be downloaded. I don't have direct access to the markup so I can't adjust the video player's settings to accommodate this, so I've been trying to do it with jQuery but can't get my head around what the correct syntax would be.
<div class="wrapper">
<div id="player">
<video><source src="video.mp4"></video>
</div>
</div>
$(function() {
var video = $('.wrapper video')[0];
$("#player").prepend($(video).attr('src'));
});
Upvotes: 0
Views: 45
Reputation: 27051
You are missing the source
tag, in your jquery.
$(function() {
var video = $('.wrapper video')[0];
$("#player").prepend('<a href=' + $("source", video).attr('src') + ' >link</a>');
});
Demo
$(function() {
var video = $('.wrapper video')[0];
$("#player").prepend('<a href=' + $("source", video).attr('src') + ' >link</a>');
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="wrapper">
<div id="player">
<video><source src="video.mp4"></video>
</div>
</div>
Upvotes: 1