How change the video tag poster attribute with javascript?
Asked Answered
H

4

14

I want to use either native JavaScript or jQuery to change the poster attribute on the HTML video tag. Any help would be greatly appreciated.

<div id="videoplayer" class="video-player" style="overflow: hidden; width: 582px; height: 326px; "> 
    <div id="myPlayer"> 
        <video id="htmlFive" width="100%" height="100%" controls="" poster="undefined">
            <source src="blank.m3u8">
        </video>
</div> 
     </div>

Thank you!

Hypophysis answered 10/10, 2012 at 19:2 Comment(0)
L
22

To do it natively, just change the attribute:

document.getElementById('htmlFive').setAttribute('poster','newvalue');

Leukorrhea answered 10/10, 2012 at 20:46 Comment(0)
P
10

Use jQuery's attr method, e.g:

$('#htmlFive').attr('poster', 'newvalue')

Or native setAttribute:

document.querySelector('#htmlFive').setAttribute('poster', 'newvalue')
Piegari answered 10/10, 2012 at 19:3 Comment(2)
Thanks this works perfect for jQuery, but now I am trying to do it natively.Hypophysis
Is there a way to re-set the poster when the video pause ?Groom
M
-4
$('#video source').attr('src', srcPath);
Misty answered 10/10, 2012 at 19:4 Comment(0)
C
-5
$("#example_video_1 .vjs-poster").css('background-image', 'url(http://video-   js.zencoder.com/oceans-clip.jpg)').show();
Chor answered 1/8, 2013 at 4:9 Comment(1)
This sets a background image - not the video poster.Metalware

© 2022 - 2024 — McMap. All rights reserved.