Is there any difference between identifying an HTML element by class/id or by a custom attribute?
I mean, for example, if I have a menu and I want to change the color of the current (active) li
element, I currently use this:
<style>
li[active]{color:red}
</style>
<ul>
<li active>...</li>
<li>...</li>
</ul>
But the most common usage is:
<style>
li.active{color:red}
</style>
<ul>
<li class="active">...</li>
<li>...</li>
</ul>
So what is the difference between them? I mean, they have the same result, but why don't people use the first method I wrote? That is much more simple and results in cleaner HTML source code.
Just for those who don't get the question... The first snippet I wrote is identifying an element BY HTML5 ATTRIBUTE. The second snippet is identifying an element BY CLASS.
So the question again: What's the difference between identifying an HTML element by HTML5 ATTRIBUTE and CLASS OR ID NAME?