With MVC and jQuery I am making significantly more use of CSS. A question that came to mind is what is the best approach for using Element IDs vs. Classes. If I use Element IDs the selectors in jQuery are shorter. For example:
#imageTag... $('#imageTag')
#searchTag... $('#searchTag')
As an alternative it could be structured with a parent container element.
#searchTool, #classifyTool .tag
In this case selectors such as
$('#searchTool .tag') or $('#classifyTool .tag')
could be used. This approach can be particularly useful when there are multiple instances of a class throughout the page, e.g., .tag. You just change the parent container object.
This is just a simple theoretical example and is not intended to represent real styles, just portray the concept.
So there are two questions:
Is there any impact on performance of either the page/CSS or jQuery assuming there are a large # of styles on a page?
The second approach seems more flexible and maintainable. Thoughts based upon your experiences.
Is there a better alternative approach?
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…