0

Possible Duplicate:
Can an html element have multiple ids?

Is it possible multiple id ? Can I use it like this ?

$("#example" + " #example2")

Html

<section id="example example2"></section>
Community
  • 1
  • 1
Cnz Adm
  • 3
  • 3
  • Use classes instead. Personally, in most cases I don't use Ids at all on elements, except for containers with unique ids if multiple copies of a form exist on a page or if you need to pass a target element to an ajax call or something similar. If a set of elements has no classes or ids one can still traverse through the DOM with jQuery quite easily. – Nope Oct 05 '12 at 07:52
  • I fail to see why you would need 2 id's. Why would you do anything like this `$("#example" + " #example2")`, when both of these id's target the same element? – Joonas Oct 05 '12 at 08:04
  • In fact I want to do my second example but i cant ? – Cnz Adm Oct 05 '12 at 08:05
  • To be honest, I don't understand what you are trying to do in your second example. Would you mind explaining what you are trying to accomplish with it? – Joonas Oct 05 '12 at 08:07
  • look http://jsfiddle.net/Dymxu/ i don't understand how can i use this (firstLoadedHtml + " #content") how is this code html ? – Cnz Adm Oct 05 '12 at 08:16
  • That is my point. I don't understand what you want to do, because what you have done, doesn't really make sense. So, try to explain what you are trying to do instead. – Joonas Oct 05 '12 at 08:19
  • I would like to make it http://bramvanroy.be/sectionLoaderTest/ but I can't find this html http://bramvanroy.be/sectionLoaderTest/js/sections.js I don't understand (firstLoadedHtml + " #content") this code html ? – Cnz Adm Oct 05 '12 at 08:22
  • Now I understand what that is trying to accomplish. Your example was way out of context. He is using jquery load method http://api.jquery.com/load/ - What is done in that code is basically the same as this: `$('#result').load('ajax/test.html #container');` In that site you linked, the "ajax/test.html" is taken from the links href, and "#container" is a static id. – Joonas Oct 05 '12 at 08:28
  • so what is this html code ?
    ?
    – Cnz Adm Oct 05 '12 at 08:31
  • Why would you do something like that? – Joonas Oct 05 '12 at 08:33
  • This code also takes a page from the outside ? – Cnz Adm Oct 05 '12 at 08:34
  • No. That is just a `section` with id `content` and a class `ajax/test.html`, which doesn't make any sense :/ – Joonas Oct 05 '12 at 08:35

5 Answers5

4

You should not use multiple IDs. If you need that use classes.

Riz
  • 9,703
  • 8
  • 38
  • 54
1

No It's not possible according to XHTML 1.0 Spec

HTML 4 defined the name attribute for the elements a, applet, form, frame, iframe, img, and map. HTML 4 also introduced the id attribute. Both of these attributes are designed to be used as fragment identifiers.

In XML, fragment identifiers are of type ID, and there can only be a single attribute of type ID per element. Therefore, in XHTML 1.0 the id attribute is defined to be of type ID. In order to ensure that XHTML 1.0 documents are well-structured XML documents, XHTML 1.0 documents MUST use the id attribute when defining fragment identifiers on the elements listed above. See the HTML Compatibility Guidelines for information on ensuring such anchors are backward compatible when serving XHTML documents as media type text/html.

Note that in XHTML 1.0, the name attribute of these elements is formally deprecated, and will be removed in a subsequent version of XHTML.

But according to W3 It's a YES

W3 selectors

If an element has multiple ID attributes, all of them must be treated as IDs for that element for the purposes of the ID selector. Such a situation could be reached using mixtures of xml:id, DOM3 Core, XML DTDs, and namespace-specific knowledge.

Common usage

ID's are single use and are only applied to one element. They are used to identify a single element. Classes can be used more than once. They can therefore be applied to more than one element, and more than once per element

Techie
  • 44,706
  • 42
  • 157
  • 243
0

According to XHTML 1.0 Spec, no. you can't.

Rorchackh
  • 2,113
  • 5
  • 22
  • 38
0

I think it's not (i tried it on JS fiddle), why on Earth would you need to have multiple IDs... I'm sure there's some much more elegant solution to your problem... can you specify it somehow?

Maddog
  • 4,746
  • 4
  • 14
  • 11
0

No it is not possible. ID always refer to uniqueness.

Vijay Verma
  • 3,660
  • 2
  • 19
  • 27