Reputation: 281
Hello I have dynamic videos which I tried to get the current video time but I seem to be getting undefined which i don't know why. I fire a function using on time update javascript event, however when i alert this var ok=$(e).attr('id'); i get the videos id but i dont know why when i try to get video current time i get undefined as value, these is my code dont know where i am getting it wrong.
<script type='text/javascript'>
function men(e){
var ok = $(e).attr('id');
var ol = $(e).attr('id');
// alert(ol[0].currentTime); --- GIVES ME UNDEFINED
$.ajax({
type : 'POST',
url : 'updatetime.php',
data : {ok: ok, om: om},
success : function(r)
{
}
});
}
</script>
<?php
$tl="channel";
$ooa="playing";
$played="played";
$timeline = mysqli_query($con, "SELECT * FROM plays WHERE streamers_type ='$tl' AND played !='$played' GROUP BY streamers_id ORDER BY id ASC") or die ();
while($row = mysqli_fetch_array($timeline)) {
$id = $row['id'];
$file1 = $row['file1'];
$video_name = $row['video_name'];
$video_type = $row['video_type'];
?>
<video class="uopi spinal" id="<?php echo $id ?>" style="height:180px; width:100%!important;" autoplay muted onended="run(this)" ontimeupdate="men(this)"><source src="plays/<?php echo $file1 ?>" type="<?php echo $video_type ?>"></video>
<?php } ?>
Upvotes: 0
Views: 651
Reputation: 318172
What you're doing is
var ol = $(e).attr('id');
ol[0].currentTime;
But .attr('id')
returns a string, the ID of the element, which clearly doesn't have a currentTime
property.
Try doing
$(e)[0].currentTime
instead
Upvotes: 4