I have the following function that is used to show one div and hide all others.
async function showHide(showId, hideList) {
let ele = document.getElementById(showId);
await hideList.forEach(item => {
item.style.display = 'none';
});
ele.style.display = 'block';
}
#c2,
#c3,
#c4 {
display: none;
}
li {
cursor: pointer;
}
<div>
<li onclick="showHide('c1', [c2,c3,c4]);">Show One</li>
<li onclick="showHide('c2', [c1,c3,c4]);">Show Two</li>
<li onclick="showHide('c3', [c1,c2,c4]);">Show Three</li>
<li onclick="showHide('c4', [c1,c2,c3]);">Show Four</li>
<div id="c1">Showing Item 1</div>
<div id="c2">Showing Item 2</div>
<div id="c3">Showing Item 3</div>
<div id="c4">Showing Item 4</div>
</div>
The function works great, however I was wondering if there is a faster, shorter or better way to do this? Ideally all 3 of the above combined would be great.