0

Hi,

In http://www.w3schools.com/tags/att_standard_id.asp it is written that:

The id must be unique within the HTML document.

What if I make them equal? I often use id for numbers of objects in database, e.g. id = 5

They are in deffierntent containers, for example

<div class = "x">
  <div id = "2"></div>
</div>
<div class = "y">
  <div id = "2"></div>
</div>

what could be the problem of this code? Javascript should work when I want select element by id - lets say with jquery I will select this way:

$('div.x div #2')

So it will know what element I am selecting. So what possible problems are then?

Of course according to standarts I should do soemthing like this - id = "x_2" so this way I would avoid equal id's in the document. But then when I want to get number from id I have to remove "x_" part.

3
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by McLaren
0

Try storing the value for the div's id in a hidden input. This way, you can access the value by calling the hidden value associated with the div.

0

1. The ID value can not start with a number.
2. The id MUST BE UNIQUE within the HTML document.

0

ok, but the actual question was "So what possible problems are then?" (if we don't do by the ruels). But I will have to do everything by the rules, there should be probelms somewhere anyway if I brake the rules.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.