[Javascript] Code optimization

Mike Dougherty mdougherty at pbp.com
Tue Aug 15 08:33:10 CDT 2006


<div id='filelist'>
   <img id="pfxName' ... /><label for='pfxName'>some text</label>
</div>

var aLabels = document.getElementById('filelist').getElementsByTagName('label');
for (iItem = 0; iItem < aLabels.length; iItem++) { do_something_here }

You could argue that the label tag is technically for describing a form control, but I think it 
makes sense as a general way to "label" any object.  You could also replace this tag with "<span>" 
and get rid of the 'for' attribute.  As long as you are not using span tags inside filelist, it is 
still easily selected by tag name.

On Tue, 15 Aug 2006 08:57:56 -0400
  tedd <tedd at sperling.com> wrote:
> At 2:37 PM -0400 8/14/06, Terry Riegel wrote:
>>I figured out how to reference the IMG tag. Duh, the code was very easy to change on that point. 
>>Now how to reference the text?



More information about the Javascript mailing list