Define multiple "id" in an HTML tag

Asked

Viewed 2,919 times

1

HTML allows to define several class in a single goal. Interestingly I tried to do the same, trying to define several id in a tag :

<div id="id1 id2 id3">Tester plusieurs id</div>

Didn’t work, HTML ignored all these classes.

Am I doing it wrong or simply not allowed by HTML ?

OBS : Simply a curiosity

  • 1

    Can you explain why you need different "ids"? are data you need to save or are you just experimenting and want to know why it doesn’t work?

  • Simply a curiosity

  • In that case it is duplicate of this or of this other.

  • Not exactly @Sergio

  • What’s the difference or what’s missing?

  • @Did you see my question? I wonder what information is missing from the other question? to complete there or give a more complete answer here.

Show 1 more comment

3 answers

4

Multiple ids per item is not allowed:

The value of this attribute must not contain gaps (spaces, tabulations etc.). Browsers treat inappropriate Ids that contain gaps such as if the gaps were part of the ID. In contrast to the class attribute, which allows multiple values separated by space, the elements can have only one ID.

Documentation

2

When you use an id it should be unique to your particular element (TAG). Ja a class can be repeated and can contain as many as you need in the same element.

Avoid repeating ids on the same page if you need to identify multiple elements with the same name, use class.

  • He asked about multiple different Ids in the same div. Not about equal Ids.

  • Read again "When you use an id it should be unique to your particular element (TAG)". I just added the answer

1

I don’t think you can do that friend. You can use more than one class(already created) in a class of a tag.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.