IDs should be unique according to the standards and whilst most browsers don't show errors when handed duplicate IDs it would not be a good idea to rely on that always being the case.
Making the ID unique by adding a type name to the ID would work but you need to ask why you need it. Giving an element an id is very useful when the element needs to be found, getElementById is very fast. The reason its fast it that most browsers will build an index of IDs as its loads the DOM. However if you have zillions of IDs that you never actually need to use in something like getElementById then you've incurred a cost that is never paid back.
So Conclusion is even browsers allow us to use duplicate IDs ,its not a good practice to use. And getElementById() should also give appropriate result , so better to avoid it.
No comments:
Post a Comment