0

I use DOCTYPE XHTML 1 Transitional, I have a <a> with a custom attribute with name data-reveal-id, this attribute is used by a jQuery script.

I'm not able to validate the document using W3, as data-reveal-id is not XHTML valid.

Any idea how to solve it?

Many thanks for your help

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
...

   <a href="#" data-reveal-id="modal-portfolio-awards">View</a>

Error when validating with W3

there is no attribute "data-reveal-id" [XHTML 1.0 Transitional]
GibboK
  • 71,848
  • 143
  • 435
  • 658
  • There has been a lot of discussion about this at http://stackoverflow.com/questions/994856/so-what-if-custom-html-attributes-arent-valid-xhtml. – Artyom Feb 17 '12 at 11:25
  • 1
    Is the file an actual XHTML file (served up with the `application/xhtml+xml` MIME type, etc.) If not, don't use an XHTML DOCTYPE declaration. Problem solved! – Mr Lister Feb 17 '12 at 11:27
  • @Mr Lister — The document will still be invalid, but browsers will render it using Quirks mode. Problem not solve but new problems created. – Quentin Feb 17 '12 at 11:29
  • @Quentin I meant to use the HTML5 one, of course. Silly! – Mr Lister Feb 17 '12 at 11:33
  • I solved using HTML 5 DOCTYPE thanks Mr Lister to point me in the right direction – GibboK Feb 17 '12 at 11:57

1 Answers1

2

Option 1: Don't use custom attributes

Option 2: Use (X)HTML 5 (which allows custom attributes that start data-)

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Option 3: Add a namespace and prefix the custom attribute with the namespace prefix. – Oded Feb 17 '12 at 11:25
  • 5
    @Oded — Still invalid. You would have to change the DTD to allow the second namespace. At that point you aren't writing XHTML 1.0 Transitional any more. You are writing XHTML 1.0 Transitional + Attributes From Some Other Namespace – Quentin Feb 17 '12 at 11:27