Alan2
Alan2

Reputation: 24602

Can I specify HTML data attributes as true/false or must they be strings?

I have the following code:

<li>
    <a class="button accessLink"
    data-disabled="no"
    data-href="/MyAccount/Access/Logout"
    title="Logout"><span class="smaller">LOGOUT</span></a>
</li>

I specified data-disabled as "no" but is it possible to use the values true / false ?

Upvotes: 0

Views: 1096

Answers (2)

Jukka K. Korpela
Jukka K. Korpela

Reputation: 201896

Yes, you can, in HTML5, unless you use XHTML serialization (in which case normal XML rules apply).

In HTML serialization of HTML5, the attribute syntax allows the use of the attribute name alone, in which case the implied value is the empty string. When using data- attributes in scripting (or styling), you can then use constructs that test for the presence of the attribute.

You can check out that http://validator.nu/ accepts an element like <a data-disabled>foo</a>.

Upvotes: 0

Paul
Paul

Reputation: 141935

No, HTML5 data-* attributes' values are strings.

You can of course use the strings "true" and "false".

Upvotes: 5

Related Questions