[Javascript] how to refer to (x)html elements

Roger Roelofs rer at datacompusa.com
Thu Nov 13 07:25:49 CST 2003


David,

> The real problem with "id" in HTML (and correspondingly in JavaScript) 
> is
> that it tries to do too many things.
I know you know this, but for anyone else lurking...

Repeat after me
"Just because the browser will let you doesn't mean you should!"

getElementById is singular for a reason, just like getElementsByTagName 
is plural for a reason.

> For example, one can define a CSS
> style block thusly:
>
> <style TYPE='text/css'>
> <!--
>     #normaltext { font-family: arial,helvetica,sans-serif; font-size: 
> 8pt;
> vertical-align: middle; text-indent: 0.4em; border-style: solid;
> border-width: 1pt }
> // -->
> </style>
>
> ... and then later inside a form define an input text field 
> referencing the
> id defined in the CSS block
>
> <form name='myForm' id='myForm'>
>   <center><input type='text' name='myText' id='normaltext' size=30

Your example is a case for which the css class was designed.  Like so,

<style TYPE='text/css'>
<!--
     .normaltext { font-family: arial,helvetica,sans-serif; font-size: 
8pt;
vertical-align: middle; text-indent: 0.4em; border-style: solid;
border-width: 1pt }
// -->
</style>

... and then later inside a form define an input text field referencing 
the
_class_ defined in the CSS block

<form name='myForm' id='myForm'>
   <input type="text" name="myText" id="myText" size="30"  
class="normaltext" />

Roger,

Roger Roelofs                          Phone 616 574-0480 x246
Datacomp Appraisal Services            Fax   616 574-0486
3215 Eaglecrest Drive, NE  Suite 100   email rer at datacompusa.com
Grand Rapids, MI  49525-4593           web   www.datacompusa.com




More information about the Javascript mailing list