Utilizing the onClick
function for each triggering element, I have implemented a show/hide feature for multiple element IDs upon click. The default setting is to hide the show/hide elements using CSS display property, except for the initial 3 main elements. As the list of triggering elements and show/hide elements grows, the script can become inefficient and repetitive. Is there a more efficient way to achieve this without resorting to extensive duplicate javascript code? The following snippet provides a simplified version of the script.
function trigger1(){
document.getElementById('trigger1').style.display ='none';
document.getElementById('trigger2').style.display ='none';
document.getElementById('trigger3').style.display ='none';
document.getElementById('element1').style.display ='block';
document.getElementById('element2').style.display ='block';
document.getElementById('element3').style.display ='block';
document.getElementById('element4').style.display ='none';
document.getElementById('element5').style.display ='none';
document.getElementById('subelement1').style.display ='none';
document.getElementById('subelement2').style.display ='none';
document.getElementById('subelement3').style.display ='none';
}
function trigger2(){
... // (rest of the original code omitted for brevity)
}
function triggerBack(){
... // (rest of the original code omitted for brevity)
}