I have a page where there is a tag with id, but a regular css class, like this one:
<div id='stack_overflow_example' class='title'> ... </div>
As you know, this one idshould be unique on this page, and I use it only to easily find it under css (for example, it can be used for ajax requests, but it’s not).
Reading about css locators (selectors), I found that I should not use identifiers as css selectors, because this will closely link my css code with my html code.
Ok, I agree. But the option is to put a unique css class in this tag and then use it in the css code.
Why is this option not as closely related as the first?
Can anyone give any other reason than what I just thought: "Because in this second option you can reuse" unique "css on other" unique "tags too."
EDITED : Reflecting on the reason for performance, my friend just thought (and I agreed):
- Using the 'id' tag, the “search” will go through the entire html code until it finds the first use of the identifier, and then stops because “id” is
unique - Using a "unique class", the "search" will go through all the html code before EOF, because many elements can have this "unique class"
Is there, at the end of the edge, a performance improvement that improves option 1?
source