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.

2

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. At that time I wasn't using HTML5. So the correct answer would be, "no, it is not valid XHTML".

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.