Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #12484
| From | Dr J R Stockton <reply1210@merlyn.demon.co.uk> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Referring to Controls by id |
| Date | 2012-03-07 21:26 +0000 |
| Organization | Home |
| Message-ID | <V9t6mRLYK9VPFw+y@invalid.uk.co.demon.merlyn.invalid> (permalink) |
| References | <191dl7ltuts723trrgoj29mln2b3uvqflk@4ax.com> <en2dl7ttlc120rthego0g2fuspsu73c9k3@4ax.com> <hg5dl7pk5ot1s5nvl2ob3t1vi8p4jldea6@4ax.com> |
In comp.lang.javascript message <hg5dl7pk5ot1s5nvl2ob3t1vi8p4jldea6@4ax.
com>, Tue, 6 Mar 2012 15:02:24, Gene Wirchenko <genew@ocis.net> posted:
>
> No, I did not. I thought I was going to be able to get rid of
> document.getElementsByName(mumble)[0]
>I suppose I still can, but now I need
> <input id=mumble name=mumble...>
AFAICS, JavaScript in a well-designed page should not need to use any
IDs at all. It is at most necessary that all elements of the DOM tree
(apart from document) that will be referred to by JavaScript, and all of
their ancestors, should have names.
A parent element "knows" the names of all of its children, and it knows
its own parent; but it does not know the names of its other descendants.
Exception : a form element knows the names of all its descendant
controls. I don't know what happens if a form's ancestor chain includes
another form - whether the ancestral form knows what controls are within
the descendant form.
I wonder how long newbies take to discover that one can easily and
sufficiently quickly walk the entire DOM tree or a branch thereof,
peering at each element in turn ?
Cut from something that works, but not tested as is :
IDees = {}
function WalkTree(Arg) { var IDee, El = Arg.firstChild
while (El) { if (El.id) { IDee = El.id ; IDees[IDee] = true }
WalkTree(El)
El = El.nextSibling } } // end WalkTree
I don't recall whether anything has been said about anchors matching
IDs. It might be allowed, but it could cause confusion if matches were
used as a link destination. I don't allow myself to do it for long.
--
(c) John Stockton, nr London, UK. ?@merlyn.demon.co.uk Turnpike v6.05 MIME.
Web <http://www.merlyn.demon.co.uk/> - FAQqish topics, acronyms and links;
Astro stuff via astron-1.htm, gravity0.htm ; quotings.htm, pascal.htm, etc.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 14:03 -0800
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 09:23 +1100
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 15:02 -0800
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 19:08 +1100
Re: Referring to Controls by id "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-07 10:44 +0200
Re: Referring to Controls by id Jeff North <jnorthau@yahoo.com.au> - 2012-03-07 23:32 +1100
Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-07 21:26 +0000
Re: Referring to Controls by id Denis McMahon <denismfmcmahon@gmail.com> - 2012-03-07 01:31 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-06 22:33 -0800
Re: Referring to Controls by id Dr J R Stockton <reply1210@merlyn.demon.co.uk> - 2012-03-08 19:06 +0000
Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-07 10:26 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-07 08:55 -0800
Re: Referring to Controls by id "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-08 09:44 +0000
Re: Referring to Controls by id Gene Wirchenko <genew@ocis.net> - 2012-03-08 19:26 -0800
csiph-web