im using this code right now

<script type="text/javascript">
    function retract() {
  		document.getElementById("ret-banner").id = 'exp-banner';
  	function expand() {
  		document.getElementById("exp-banner").id = 'ret-banner';
  		setTimeout('retract()', 3000)
but i need it to get the element by class instead. I tried just by changing it to document.getElementByClassName but it didnt work. Why? Could you please give me some ideas?

Thank you.