I have a site I\'m working on where I want to mark if a row of data has been changed. If something has been changed in that row I would mark it with a custom attribute like
Technically you should be using the class attribute for this. Tags can have more than one class so it shouldn't affect anything
<td class="isDirty otherclass">
Years ago I used custom attributes, and they work. Doing the same following the html 5 standard, will avoid future problems, because past problem do not exist. future problems may come with movil devices and other devices different than a computer, but, as they will be part of the near future, stick with html 5 custom attributes if you want to use them. My new case is simple, what I do, is to use tags well coded, with simple data in between (variable data) which I get via nodeValue having your element ... this.firstChild.nodeValue and the key is to make the used tag display none by style how you get this? getelementbyID, by tagname, by name, by classname you choose. Advantages No need to encode decode entities, etc., no need jquery
This will prevent your page from validating I think, since you are adding custom attributes that the validators won't know about.
You might be able to do this with your own DTD or schema, but that's more work.
Your second example is the right way to do this I think. The right direction anyway.
Sticking to the standards for the sake of sticking to the standards is a bad reason to stick to standards.
Your page specifies the DTD, your server specifies the mimetype. As long as you aren't sending real xhtml there is no reason not use expando attributes in this way. It can be very helpful.
Ok so your page won't 'validate' if you need to care about that then don't do it.
Just don't be seduced by IEs 'conveniant' elem.isDirty method of accessing such values. Always use elem.getAttribute('isDirty') to access the value.
Adding arbitrary attributes will mean that your HTML is no longer valid.
If you are using XHTML, however, I think you can add attributes that have a different XML namespace, which won't cause validation problems.
I don't know a great deal about this, but thought I'd mention it as no one else has. Perhaps someone else could expand on, or refute, this if they have a better understanding?