Search code examples
htmlxhtml-1.0-strictcustom-data-attribute

Custom data in XHTML 1.0 Strict


I use some custom attributes in my html, for jquery stuff. I saw there are data-XYZ attributes in HTML5, but I need to be xhtml 1.0 strict. What other options do I have?


Solution

  • You can use the jQuery MetaData plugin which allows you to write data in the class attribute in JSON format:

    <li class="someclass {some: 'data'} anotherclass">...</li>
    

    Then in your jQuery, to get at the data:

    var data = $('li.someclass').metadata();
    if ( data.some && data.some == 'data' )
        alert('It Worked!');
    

    This should meet your requirements of being xhtml 1.0 strict, and also allows you to use a plug-and-play solution :)