Hiding all elements with a given tag except one
Over 10 years ago, I made my first show/hide toggler and was very proud of it… and tonight I had to remember how to do these basics.
My script searches for section elements and hides all but the specified one — this will eventually be used as a way of handling my paginated quiz (each section being a “page”).
function hideAllButOne(displayDiv){ var sections = document.getElementsByTagName('section'); for (var i = 0; i < sections.length; i++) { var section_id = sections[i].getAttribute('id'); if (section_id == displayDiv){ sections[i].style.display = 'block'; } else{ sections[i].style.display = 'none'; } } }
I have a lot left to do, but this is a start.
Leave a Reply