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!

Justin
  • 416
  • 3
  • 9
  • 26

4 Answers4

22

To do it natively, just change the attribute:

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

TimHayes
  • 3,684
  • 21
  • 26
10

Use jQuery's attr method, e.g:

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

Or native setAttribute:

document.querySelector('#htmlFive').setAttribute('poster', 'newvalue')
Dominic
  • 62,658
  • 20
  • 139
  • 163
-4
$('#video source').attr('src', srcPath);
Steven Hunt
  • 2,321
  • 19
  • 18
-5
$("#example_video_1 .vjs-poster").css('background-image', 'url(http://video-   js.zencoder.com/oceans-clip.jpg)').show();
pigletfly
  • 1,051
  • 1
  • 16
  • 32