Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #12460
| From | Ross McKay <au.org.zeta.at.rosko@invalid.invalid> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: CSS Use of ID |
| Message-ID | <jrbdl71glpiejf86l2jo055v5bimuoetvu@4ax.com> (permalink) |
| References | <qhabl79jrmuqqhda7kvu7mce8me5n9aoe9@4ax.com> |
| Organization | EasyNews, UseNet made Easy! |
| Date | 2012-03-07 11:58 +1100 |
On Mon, 05 Mar 2012 22:15:50 -0800, Gene Wirchenko wrote:
> 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?
You can use CSS classes to tie related elements together, or you can
store your data in other attributes. With HTML5, you can use custom data
attributes[1], like so:
<p id="p1234" data-bar="foo">A foo</p>
<p id="p1235" data-bar="foo">Another foo</p>
You can then select them with querySelectorAll[2] like so:
<script>
var elements = document.querySelectorAll('[data-bar="foo"]');
...
</script>
(I say "with HTML5", but really this will work in modern browsers except
the IE browsers in IE7 compatibility mode)
[1] http://www.w3.org/TR/html5/elements.html
#embedding-custom-non-visible-data-with-the-data-attributes
( http://preview.tinyurl.com/7f7v4mc )
[2] https://developer.mozilla.org/En/DOM/Element.querySelectorAll
--
Ross McKay, Toronto, NSW Australia
"Let the laddie play wi the knife - he'll learn"
- The Wee Book of Calvin
Back to comp.lang.javascript | Previous | Next — Previous in thread | Find similar | Unroll 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