I have a function that gets multiple ids at once, but I have to do slightly different operations on each one, so I'm forced to create 3 variables for each different id. The idea is that if there is html content in id3, ids 1 and 2 should not be displayed, which leads to another repeat of style.display='none'
. I tried to create a variable ( var s = s.style.display='none'
) to simplify the application, but I do not know how to apply it. My question is whether there is a way to reduce the amount of getElementById
from 3 to 1, as well as style.display='none'
., Or anything else that reduces the number of repetitions. Thank you in advance for your attention.
function IDs(id1, id2, id3) {
var a = document.getElementById(id1);
var b = document.getElementById(id2);
var c = document.getElementById(id3);
var s = s.style.display='none'; // variável para aplicar estilo
if (a.innerHTML) {
c.style.display='none';
}
else {
a.style.display='none';
b.style.display='none';
}
}