0
I’m trying to get a video element from CLASS,(something that seems silly to me), But I’m not getting it, take my example:
<script src="jquery-3.2.1.js"></script>
<video id="Video1" class="video-stream" src="https://www.html5rocks.com/pt/tutorials/video/basics/Chrome_ImF.mp4">
</video>
<div id="buttonbar">
<button id="play" onclick="vidplay()" >></button>
</div>
<script>
function vidplay() {
// com JS e pegando pelo ID funciona bem:
var video = document.getElementById("Video1");
// com JS e pegando pela CLASS nao vai...
//var video = document.getElementsByClassName("video-stream");
// com JQUERY NADA VAI! ..
//var video = $("#Video1");
//var video = $(".video-stream");
// um teste....
$.each( $( ".video-stream" ), function() {
console.log( " MESSAGE ====> | id = " + this.id );
});
// o erro aparece quando dou play no video...
video.play();
}
</script>
I need to get that element of < video > by his CLASS... someone can tell me what’s wrong here?
+1 for incrementing jQuery in the answer. In this case, obtaining an element by class is more relaxed by jQuery than by pure Javascript
– Gabriel Polidoro
YES I need to pick by class. And thank you so much for the help, now I can do a js and jquery!!! Well I’m still studying java... I have a lot to learn!!! And of course I didn’t realize I had to take the first element...!!!!
– Camila Yamamoto