Is using the same id multiple times on a page bad practice even when I am not parsing through the page?

后端 未结 4 1732
广开言路
广开言路 2021-01-18 01:36

I understand that using the same id multiple times in a page creates malformed html. When using a jquery selector only the first element with the id will be returned, but in

4条回答
  •  难免孤独
    2021-01-18 02:21

    You only know what the current requirements are.

    It is best to keep to standards and to valid code/markup as you don't know what will happen in the future.

    In this application, you may very well end up having to use jQuery and then you will be in trouble.

    The solution for styling multiple elements the same way is to use CSS classes - there is absolutely no reason not to do so, as it is just as simple as using ids.

提交回复
热议问题