repetition of content informed by . html()

Asked

Viewed 35 times

2

I inform through JQUERY the link to open a video in a modal

<video width="100%" height="400" id="vid_video" controls="controls" style="padding: 0 10px 0 10px">
<!-- AQUI DENTRO VAI O <source></source> vindo do JQUERY -->
</video> 

JQUERY passes the video path and name:

 $('#visualizarVideo').on('show.bs.modal', function (event) {
var button = $(event.relatedTarget)
var vid_video = button.data('video') //captura o valor do data-video
$("#vid_video").html('<source src="../upload/'+vid_video+'" type="video/mp4"></source>' );
//vid_video recebe por exemplo video.mp4

beauty, it’s working. But I have a table with information coming from the BD by a loop, and each row of the table is a different video. If I click on a video and close right away, the next video is the same! As if jquery did not implement "data-video". I hope what I said is understandable.

Inside the loop I inform through the data-video the address.

<li><a href="#" data-video="<?php echo $videos->vid_video ?>" data-toggle="modal" data-target="#visualizarVideo" >Visualizar</a></li>

Personal thank you! :)

  • What you’re putting in the variable button?

  • Thank you for answering sam. Voce refers to: var vid_video = button.data('video') ? if yes, this coming inside the <li> to store where the video is.

  • 1

    Blz. But had to see how you are assigning value to variable button.

  • Ah understood now. sorry. I updated the code! from a look.

1 answer

5


If you just change the source, the browser caches the first video run. What you should do is change the tag video all.

div that will receive HTML:

<div id="vid_video"></div>

Event:

$('#visualizarVideo').on('show.bs.modal', function (event) {
   var button = $(event.relatedTarget);
   var vid_video = button.data('video');
   var vid_html = '<video width="100%" height="400" controls="controls" style="padding: 0 10px 0 10px">'
   +'<source src="'+vid_video+'" type="video/mp4"></source>'
   +'</video>';
   $("#vid_video").html(vid_html);
});
  • phenomenal sam. exactly this solved my problem. thank you very much! =)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.