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


Groups > comp.lang.javascript > #12426

Re: CSS Use of ID

Newsgroups comp.lang.javascript
Subject Re: CSS Use of ID
From "Evertjan." <exjxw.hannivoort@interxnl.net>
References <qhabl79jrmuqqhda7kvu7mce8me5n9aoe9@4ax.com>
Message-ID <XnsA00E70997BCB8eejj99@194.109.133.133> (permalink)
Date 2012-03-06 10:04 +0000

Show all headers | View raw


Gene Wirchenko wrote on 06 mrt 2012 in comp.lang.javascript:
>      Is the issue of avoiding using the same id more than once but
> using a special CSS item really just solved with using a class instead
> of id?

Is it an issue that there are no maple trees growing in the ocean?

It is not an isssue, Gene, only if you make it one
by trying to do something that is impossible standardwize.

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. 

Also CSS use of id is off-topic here.

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

Most use getElementsBy* [with the 's']:

getElementsByName()
getElementsByTagName()
getElementsByClassName()

--------------------------------------------

However, 
while I hate to acknowledge this,
Javascript being Javascript [sorry Thomas],
there is [dirty?] a way around the html single id-limitation, Gene.

Try:

==========
<style type='text/css'>
div {color:red;}
</style>
<div id=a>1</div>
<div id=a>2</div>
<div id=b>3</div>
<span id=a>not a div</span>
<div id=a>4</div>

<script type='text/javascript'>

var x = document.getElementsByTagName('div');

for (var i = x.length-1;i>-1;i--)
 if (x[i].id == 'a')
  document.write('<br>'+x[i].id+' > ' + x[i].firstChild.nodeValue);

</script>
==========


-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

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