Struppi: document.getElementById(lastOpenedBox) has no properties

Beitrag lesen

PS: Ich habe gerade nocheinmal ein bisschen herumprobiert. Dabei kam das heraus:
#######
var lastOpenedBox = null;
function openBox(box){
    if(lastOpenedBox != null){
  closeBox(lastOpenedBox);
  document.getElementById(box).style.display = "block";
  lastOpenedBox = box;
} else {
document.getElementById(box).style.display = "block";
    lastOpenedBox = box;
}
}

Das ist doch arg umständlich.
Du rufst hier insgesamt bis zu dreimal getElementById auf obwohl's nur einmal nötig wäre.

  
var lastOpenedBox = null;  
function openBox(box_id)  
{  
if(lastOpenedBox) lastOpenedBox.style.display = 'none';  
lastOpenedBox = document.getElementById(box_id)  
lastOpenedBox .style.display = "block";  
}  

Struppi.

--
Javascript ist toll (Perl auch!)