Targeting a sub element to change CSS styles

What I want to do is close all the tab-panels and then open the target panel

Seems like the code could be two lines in a function
function switchPanel(target) 
  {
  [display:none all elements with class="panel"]
  document.getElementById(target).style.display = "inline";
  }

Any ideas?

*
This is for a set of tabs and panels. I already know how to do by id-ing all the panels and looping through an array to close them all then open the requested one, but I am looking for fewer lines of code that requires less id-tags (genral solution)

I've done it before by
document.getElementById(panelsetname).getElementsByTagName('div')

But then you can't have any sub divs. I've looked online but all the solutions I have found are longer than the one I am already using.