Skip to content Skip to sidebar Skip to footer

Unique Id Value In Html

This is a question more out of curiosity rather than being stuck. I know in html id needs to be unique and I can see the error in html validation. Yet the browsers happily apply st

Solution 1:

If your browser died every time it loaded an HTML page with errors, it'd be dying all the time. And you wouldn't think very much of the browser.

It's important for a browser to be as forgiving as possible and work as best it can with what it has. For this reason, all browsers tend to be very lenient in how they handle markup.

Of course, that doesn't mean you shouldn't write valid HTML.

Solution 2:

I would not rely on that behaviour. Having two elements with the same ID is just wrong as you already know.

And yes, the tolerate errors in HTML to some extend and try to compensate. For example missing closing tags. This works more or less good, depending on the error.

Styling several elements should be done with CSS classes.

Solution 3:

use "class" for adjusting css.

side effect: you'll feel less comfortable when you want use getElementById and add dynamic functionality. from design perspective doesn't matter.

Post a Comment for "Unique Id Value In Html"