[Solved] Uncaught reference error: image not defined [closed]


There is no reference to an image variable in the code below – it is, as the error suggests, not defined.

function changeImage() {
    var square = document.getElementById('first');
    if (image.src.match("https://stackoverflow.com/questions/31943377/square1.png")) {
        image.src = "https://stackoverflow.com/questions/31943377/squareblue1.jpg";
    } else {
        image.src = "https://stackoverflow.com/questions/31943377/square1.png";
    }
}

All you have to do is change the square variable to image, I assume.

function changeImage() {
    var image = document.getElementById('first');
    if (image.src.match("https://stackoverflow.com/questions/31943377/square1.png")) {
        image.src = "https://stackoverflow.com/questions/31943377/squareblue1.jpg";
    } else {
        image.src = "https://stackoverflow.com/questions/31943377/square1.png";
    }
}

solved Uncaught reference error: image not defined [closed]