1

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.

Francisc
  • 77,430
  • 63
  • 180
  • 276
  • 1
    See [ Custom attributes - Yay or nay? ](http://stackoverflow.com/questions/992115/custom-attributes-yay-or-nay) and [ So what if custom HTML attributes aren't valid XHTML? ](http://stackoverflow.com/questions/994856/so-what-if-custom-html-attributes-arent-valid-xhtml). – Matthew Flaschen Sep 17 '10 at 23:10
  • Excellent, Matthew. Thanks. Either paste that as an answer for me to set it as the answer or someone delete my question. – Francisc Sep 18 '10 at 00:17

1 Answers1

1

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

Lucas
  • 16,930
  • 31
  • 110
  • 182
  • Thanks. At that time I wasn't using HTML5. So the correct answer would be, "no, it is not valid XHTML". – Francisc Dec 29 '12 at 16:34