Reputation: 3789
I am trying to attach a listener to my video to update the input range on some custom controls and am getting an error that reads Uncaught ReferenceError: Invalid left-hand side in assignment
$(document).on('click', '.play-pause', function() {
const video = $(this).closest('.video-container').children('video').get(0);
if (video.paused == true) {
video.play();
$(this).closest('.video-container').children('video').bind('timeupdate', function() {
let value = (100 / video.duration) * video.currentTime;
$(this).closest('.video-container').find('.seek-bar').val() = value;
})
$(this).children('svg').remove();
$(this).html(
`<i class="fas fa-pause fa-fw"></i>`
);
} else {
video.pause();
$(this).children('svg').remove();
$(this).html(
`<i class="fas fa-play fa-fw"></i>`
);
}
});
Upvotes: 1
Views: 243
Reputation: 23379
If you want to assign the value using the assignment operator you need to use plain js..
$(this).closest('.video-container').find('.seek-bar')[0].value = value;
You can only assign values to variables or properties, you got that error because you tried to assign a value to the output of a function val() = value
Upvotes: 1
Reputation: 218877
This is not how you set a value to an element in jQuery:
$(this).closest('.video-container').find('.seek-bar').val() = value;
$(this).closest('.video-container').find('.seek-bar').val(value);
As the error states, you can't use a function call as the target of a variable assignment. You assign values to variables, not to functions.
Upvotes: 2