[thelist] [DHTML] Elements with the same ID
Keith Dahlby
dahlbyk at softhome.net
Wed Mar 19 02:49:20 CST 2003
Each call to getElementsByTagName() likely generates a unique temporary
array of the appropriate elements, which wastes memory and processor
cycles. Thus for better performance (and cleaner code):
function hideall(hiddenContentElement, hiddenContentClass)
{
var hiddenElements =
document.getElementsByTagName(hiddenContentElement);
for (i=0; i<hiddenElements .length; i++)
if (hiddenElements .item(i).className == hiddenContentClass)
hiddenElements .item(i).style.display = "none";
}
That said, this is an excellent implementation using the class attribute as
it is intended. Good work David!
Cheers ~ K
At 12:33 AM 3/19/2003, David wrote:
>function hideall(hiddenContentElement,hiddenContentClass) {
> for
> (i=0;i<document.getElementsByTagName(hiddenContentElement).length; i++) {
> if
> (document.getElementsByTagName(hiddenContentElement).item(i).className ==
> hiddenContentClass){
>
>document.getElementsByTagName(hiddenContentElement).item(i).style.display
>= "none";
> }
> }
>}
More information about the thelist
mailing list