Francisc
Francisc

Reputation: 80395

XHTML: Adding `custom` attributes

Is it "ok" to add attributes to various tags to use in JavaScript DOM parsing?

For example if I want to have required fields in a form, would it be a bad practice if I would do this:

<input type="submit" name="name" required="true"/>

Thank you.

Upvotes: 1

Views: 1087

Answers (1)

Zerium
Zerium

Reputation: 17333

From that question:

HTML 5 explicitly allows custom attributes that begin with data. So, for example, <p data-date-changed="Jan 24 5:23 p.m.">Hello</p> is valid. Since it's officially supported by a standard, I think this is the best option for custom attributes. And it doesn't require you to overload other attributes with hacks, so your HTML can stay semantic.

Source: http://www.w3.org/TR/html5/elements.html#embedding-custom-non-visible-data-with-the-data-attributes

Upvotes: 1

Related Questions