[thelist] JavaScript focus & getElementByID

.jeff jeff at members.evolt.org
Thu Jan 16 12:55:01 CST 2003


martyn,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Martyn Haigh
>
> How would I go about accessing this element?
>
> 	<tr id="HearSec" name="HearSec">
>
> (Have I included enough of the HTML here?)
>
> I've tried these - but they don't work :
>
> 	document.elements['HearSec'].display = 'none';
> 	document.HearSec.display = 'none';
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

the <tr> tag does not have a name attribute and the browser doesn't build an
array of tr objects at the document level.  it does, however, build up an
array of tr objects at the table level.  but, if you want to access a
specific tr, give it an id and use the getElementById() method (make sure to
always check for support of newer methods and objects like this before
calling it to prevent errors in browsers that don't have support for them).

if(document.getElementById)
  document.getElementById('HearSec');

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> is the elements array only built up for the forms?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

yes.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> In which case - is there just a normal elements array
> built up of elements not in forms?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

sort of.  there are also collections built up for images, links, and some
other things i'm forgetting.

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Or should I stick with my old method of using a API to
> grab these out of form elements?
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

stick with your api for accessing things that aren't available in an
existing collection of some type.  for everything else, go dom 0 as much as
possible for the best browser coverage.

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list