I’ve got a dynamically built html table from the server. Ultimately it gives me a table that looks like:
<div id="player"></div>
<table id="webcam-table">
<thead>
<tr>
<th>Camera Name</th>
<th>Date Created</th>
</tr>
</thead>
<tbody>
<tr >
<td onclick="DoNav('http://myserver.com:1935/recordings/myfile1.mp4');">
Default camera
</td>
<td onclick="DoNav('http://myserver:1935/recordings/myfile1.mp4');">
06 May 2012 07:25:01
</td>
</tr>
<tr >
<td onclick="DoNav('http://myserver.com:1935/recordings/myfile2.mp4');">
Default camera
</td>
<td onclick="DoNav('http://myserver.com:1935/recordings/myfile2.mp4');">
06 May 2012 07:24:47
</td>
</tr>
...
</tbody></table>
If anyone clicks the row on the table it calls the DoNav function to insert a video.
function DoNav(theUrl)
{
var mydiv = $("#player");
var myvideo = $("<video id='myfileplayer' src='"+ theUrl +"' width='280' height='200' controls></video>");
mydiv.append(myvideo);
$("#myfileplayer").click(function(){
$(this).play();
});
}
It plays great if you click on one row in the table. But once you click on the next row it adds another player underneath and so on. I want to replace the player that is there with the new one that was just clicked. I’ve tried adding $("#myfileplayer").hide(); to the end of the DoNav function but that just hides the player overall. Any ideas?
You are appending a new player underneath the previous one.