unique ID

W

Wally S

I have always heard that an ID should be assigned to only one element on a
page. But I was just playing around, and I found that you can assign the
same ID to many things on a page, just like a class, and it works. I don't
intend to do it, but what gives? Is it simply a convention that only one
thing on a page should have a specific ID?

Wally S
 
K

Kevin Spencer

Define "it works." If by "it works" you mean that nothing bad happens when
you open the page, and you have no JavaScript or CSS that needs to
manipulate these HTML elements, yes, it works. However, the purpose of an ID
(which is not even necessary unless you plan to manipulate the object), is
to uniquely identify an HTML element for the purpose of manipulating it.
JavaScript or CSS can manipulate HTML objects, but the ID is necessary to
uniquely identify the object that is being manipulated. Apparently, you are
not using JavaScript or CSS to manipulate your HTML. Therefore, "it works."

In other words, let's say you have a car with no engine. For the purpose of
displaying it at an auto show, "it works." For the purpose of driving, it
does not.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
M

Murray

Try adding a style to your stylesheet that applies to this ID and see how
well it works. 8)
 
W

Wally S

I applied a style on the page itself, since I was only fooling around, and
it applied the style to the different occurrences of the ID, the same as it
would to a class. I'm not going to use this, as I am sure it could cause
problems down the road, but I thought I would mention it, as a curiosity of
sorts.

I was experimenting with some formatting. Then I wanted to see what would
happen if I applied an already-existing ID to a second item. Would FP move
the ID or would it reject the second one? It did neither. IE does not reject
it either.

Wally S
 
M

Murray

That's right - FP won't reject it.

Try doing an show/hide layer when you have two layers with the same ID.
 
W

Wally S

Hi Murray,

I'm not arguing for it, and I don't intend to use it, but I thought it was
worth mentioning. I am sure the example you give would not work. I was only
formatting paragraphs with it. But still, the principle is there.

Wally S
 
M

Murray

FP will not stop you from using the same ID in multiple places on the page.
You should stop you from doing it! 8)
 
K

Kevin Spencer

But still, the principle is there.

I wouldn't be so sure. How many different browsers did you test it in?

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
W

Wally S

True, I only tested it in two, IE and Netscape, and I am not going to go any
further with it because it is non-standard and potentially troublesome, but
I was surprised, and I wondered if anyone had anything more to say about it.

Wally S
 
W

Wally S

Pretty funny example. I had no intention of using this, but I accidentally
did by unthinkingly copying two things with the same ID from two different
pages onto a third page and found out that although it may work on some
pages, it won't work on others. Neither one of the identical IDs got
formatted. So now my curiosity is satisfied.

Thanks to everyone for taking the time.

Wally S
 
Top