'Javascript click event not reverting according to my statement

I'm trying to revert my click event after clicking but my else statement seems not to be working, I do not know if something is wrong with my code:

var img = document.querySelector ('.change');

img.addEventListener('click', function(){
    if(img.src = 'homepage imgs/inactive.svg') {
        img.src = 'homepage imgs/like icon.svg';
    } else{
        img.src = 'homepage imgs/inactive.svg';
    }
});


Solution 1:[1]

you are actually assigning rather than comparing a single = is used to assign like

a = 10;

a double == is used for comparison, like whether a is equal to 10 or not

like a==10;

to fix your issue change to

if(img.src == 'homepage imgs/inactive.svg') 

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Faizal Hussain