Changing two images simultaneously with one button-onclick and querySelector
16:37 13 Oct 2026

I'm trying to use onclick and querySelector to do the following: there's four buttons->each button is connected to two, overlapping images(i plan to put more images in between them, so they have to be separated)->the two default images change at the same time when a button is clicked---no hide/show toggle.

I've tried many combinations. Is it possible to do this with these commands? Or should i do something else?

HTML:



Javascript:

function changeImg(pngs) {

    let img = document.querySelectorAll("#imgSet1, #imgSet2");

    img.setAttribute("src", pngs);

}
javascript onclick queryselector