PDA

View Full Version : Syntax Correct?


unclhos
06-19-2009, 04:30 AM
I have a set of photos on different sliders.
The different divs are populating correctly before I put in the display: none;
Is my Syntax correct for my javascript function embedded in an Iframe?

function showPhotos(str)
{
parent.document.getElementByClass('photoslider').style.display="none";
parent.document.getElementById(str).style.display="inline";
}

Kor
06-20-2009, 07:22 PM
getElementsByClassName() is the correct method and it returns a collection of elements, not a single element. You must circle trough them.

var elem=parent.document.getElementsByClassName('photoslider'), i=0, e;
while(e=elem[i++]){
e.style.display='none';
}


Note: getElementsByClassName() was not implemented in IE 6, nor in IE7. See also:
http://www.codingforums.com/showthread.php?t=154727