Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #12427

Re: CSS Use of ID

From "Jukka K. Korpela" <jkorpela@cs.tut.fi>
Newsgroups comp.lang.javascript
Subject Re: CSS Use of ID
Date 2012-03-06 12:37 +0200
Organization A noiseless patient Spider
Message-ID <jj4pdl$5m4$1@dont-email.me> (permalink)
References <qhabl79jrmuqqhda7kvu7mce8me5n9aoe9@4ax.com> <XnsA00E70997BCB8eejj99@194.109.133.133>

Show all headers | View raw


2012-03-06 12:04, Evertjan. wrote:

> More so, if you accidentaly use an id more than once, most browsers will
> forgive you your grave error and only use the first id.

I wouldn't count on that. I've seen situations where browsers behave as 
if no element had the id. This might even be seen as better error 
recovery: when something is supposed to uniquely identify some element, 
ignore it when it is multiply defined (instead of making a guess).

> However if you want to make a javascript collection of html-elements,
> there are many ways to do that.

Indeed. Using the id attribute value is fine when it is applicable, but 
not so when it is not.

> Most use getElementsBy* [with the 's']:
>
> getElementsByName()
> getElementsByTagName()
> getElementsByClassName()

These have varying limitations. In particular, getElementsByClassName() 
is not universally supported, so it is safer to process elements e.g. on 
the basis of tag name and just pick up those that belong to a specific 
class, or to use a library such as jQuery that does such things behind 
the curtains.

-- 
Yucca, http://www.cs.tut.fi/~jkorpela/

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

CSS Use of ID Gene Wirchenko <genew@ocis.net> - 2012-03-05 22:15 -0800
  Re: CSS Use of ID "Evertjan." <exjxw.hannivoort@interxnl.net> - 2012-03-06 10:04 +0000
    Re: CSS Use of ID "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-06 12:37 +0200
      Re: CSS Use of ID Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-06 04:24 -0800
        Re: CSS Use of ID "Jukka K. Korpela" <jkorpela@cs.tut.fi> - 2012-03-06 15:21 +0200
      Re: CSS Use of ID David Mark <dmark.cinsoft@gmail.com> - 2012-03-12 17:09 -0700
  Re: CSS Use of ID Norman Peelman <npeelmandog@cfl.rr.com> - 2012-03-06 06:40 -0500
    Re: CSS Use of ID Gene Wirchenko <genew@ocis.net> - 2012-03-06 11:27 -0800
      Re: CSS Use of ID Denis McMahon <denismfmcmahon@gmail.com> - 2012-03-07 01:49 +0000
      Re: CSS Use of ID Norman Peelman <npeelmandog@cfl.rr.com> - 2012-03-06 23:13 -0500
        Re: CSS Use of ID Gene Wirchenko <genew@ocis.net> - 2012-03-06 22:32 -0800
  Re: CSS Use of ID Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-06 04:36 -0800
    Re: CSS Use of ID Gene Wirchenko <genew@ocis.net> - 2012-03-06 11:29 -0800
  Re: CSS Use of ID Ross McKay <au.org.zeta.at.rosko@invalid.invalid> - 2012-03-07 11:58 +1100

csiph-web