HTML attribute custom attribute

Possible duplicates:
Saving arbitrary information in HTML tags for JavaScript?
What are the specific risks of using custom HTML attributes?
Custom attributes - Yay or nay?

What are the disadvantages of adding a custom attribute to a standard HTML element?

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

By adding MyCustomAttribute, I invalidated the document, but what are the actual implementations? What problems, if any, will be the cause?

I would use Javascript to read user attribute values.

thanks

+6
javascript html
source share
5 answers

The downside is that you cannot use validation tools because they will complain about the โ€œinvalidโ€ attribute.

HTML5 provides us with the right path though (huzzah!): Use the data- prefix for your own attributes, like data-mycustomattribute . And it works today in all major browsers.

+9
source share

This can lead to compatibility issues sooner or later.

Rather, the prefix of the attribute name is data- , for example. data-MyCustomeAttribute . There it is for .

0
source share

Typically, most browsers ignore attiributes, which they cannot understand. However, there must be another way to do what you are trying to do with valid markup.

0
source share

I believe this is part of the specification for HTML5, and therefore use <html> doctype to verify it. But, as we all know, HTML5 is not yet fully implemented in browsers, so you have to wait a bit to check

0
source share

You can combine the correctness and customization if you start from the xml source using your own dtd and convert it to (valid) html using javascript.

0
source share

All Articles