views:

165

answers:

5

Possible Duplicates:
Storing arbitrary info in HTML tags for JavaScript?
What are the concrete risks of using custom HTML attributes?
Custom attributes - Yay or nay?

What are the drawbacks of adding a custom attribute on a standard HTML element?

For example:
<intput type="textbox" id="MyId" MyCustomeAttribute="MyData" />

By adding the MyCustomAttribute, I've made the document invalid, but what are the actual implecations? What problems, if any, will this cause?

I'd be using Javascript to read the values of the custom attributes.

Thanks

A: 

It may cause compatibility problems sooner or later.

Rather prefix the attribute name with data-, e.g. data-MyCustomeAttribute. There it is for.

BalusC
+4  A: 

The drawback is that you can't use validation tools, because they'll complain about an "inavlid" attribute.

HTML5 provides a way for us to do this validly, though (huzzah!): Use the prefix data- for your own attributes, e.g., data-mycustomattribute. And it works today in all major browsers.

T.J. Crowder
A: 

Usually most browser ignore attiributes they can't understand. However there should be another way to do what you are trying to do with a valid markup

Sinan
A: 

I believe it's part of the spec for HTML5 and should therefor validate using a <html> doctype. But as we all know HTML5 is not fully implemented yet across browsers so you your going to have to wait a while for it to validate

Nick Allen - Tungle139
A: 

You can combine validatability and customizability if you start from an xml source, with your own dtd, and transform it to (valid) html with your javascript.

xtofl