Sandra Willford
Sandra Willford

Reputation: 3789

Uncaught ReferenceError: Invalid left-hand side in assignment on bind()

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

Answers (2)

I wrestled a bear once.
I wrestled a bear once.

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

David
David

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 is:

$(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

Related Questions