Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom Attribute on HTML Element [duplicate]

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

like image 808
Craig Avatar asked Mar 10 '10 15:03

Craig


1 Answers

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

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

like image 146
T.J. Crowder Avatar answered Sep 27 '22 16:09

T.J. Crowder