Search code examples
htmlbackbone.jshtml-parsingmarionettebackbone-views

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


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 my application I shouldn't be running into this issue.

I have list of items views that will all have an element I need to refer to. Since each item only has access to its own $el passing in an id selector for something will not produce any conflicts (even if there are multiple on the page).

I've simulated what I mean in a fiddle here

In this project I am not doing any page wide parses so I believe it should be safe. Is there any reason why I should not be doing this?


Solution

  • 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.