[Javascript] How to refer to an HTML element's ID attribute

David Lovering dlovering at gazos.com
Fri Nov 14 01:11:28 CST 2003


... Or if you are doing a traverse of a form's elements you can use
something like this --

var numElements = document.forms[0].elements.length;
for (var i=0; i<numElements; i++) {
  var localElementID = document.forms[0].elements[i].id;
  document.write("<left>" + localElementID + "</left><br>\n");
}

In theory, you can access any object's id by this method (assuming that it
is defined).

-- Dave Lovering

----- Original Message ----- 
From: "BEKIM BACAJ" <trojani2000 at hotmail.com>
To: <javascript at LaTech.edu>
Sent: Thursday, November 13, 2003 9:58 PM
Subject: Re: [Javascript] How to refer to an HTML element's ID attribute


> take this;
> if elements ID is ID="myelement"
> you an refere to it simply with:
> myelement.style.pixelWidth='100' f.i., this is direct access and attribute
> set through js
> any other reference to it is simply its id name.
>
>
> >From: Robert Pollard <rpollard at apple.com>
> >Reply-To: "[JavaScript List]" <javascript at LaTech.edu>
> >To: javascript at LaTech.edu
> >Subject: [Javascript] How to refer to an HTML element's ID attribute
> >Date: Thu, 13 Nov 2003 15:59:11 -0800
> >
> >Hello all,
> >
> >What is the syntax to refer to an HTML element's ID attribute?
> >
> >Thanks,
> >
> >Robert Pollard
> >
> >_______________________________________________
> >Javascript mailing list
> >Javascript at LaTech.edu
> >https://lists.LaTech.edu/mailman/listinfo/javascript
>
> _________________________________________________________________
> STOP MORE SPAM with the new MSN 8 and get 2 months FREE*
> http://join.msn.com/?page=features/junkmail
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list