I have some JS code below which basically stands for: when the element with x1 ID is hovered make the element with the x1-1 ID visible and then on mouseout
return to the default hidden. The problem is that I have a few more ID pairs (x2 & x2-1, x3 & x3-1 etc) that need the same code applied, and I don't want to repeat the code 5 or 6 times. Is there a smart way of wrapping it up in a few lines of code?
document.getElementById("x1").addEventListener("mouseover", mouseOver);
document.getElementById("x1").addEventListener("mouseout", mouseOut);
function mouseOver() {
document.getElementById("x1-1").style.visibility = "visible";
}
function mouseOut() {
document.getElementById("x1-1").style.visibility = "hidden";
}