Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 319
cambraca Avatar asked Nov 15 '10 21:11

cambraca


People also ask

What is XHTML 1.0 strict?

XHTML 1.0 Strict is the XML equivalent to strict HTML 4.01, and includes elements and attributes that have not been marked deprecated in the HTML 4.01 specification. As of November 2015, XHTML 1.0 Strict is the document type used for the homepage of the website of the World Wide Web Consortium.

Is XHTML strict?

XHTML 1.0 Strict is the same as HTML 4.01 Strict, but follows XML syntax rules. In particular, it does not allow the use of presentational elements such as center , font or strike . Presentational attributes such as align , bgcolor and background are similarly banned. Furthermore, it does not allow frames or applets.

What is DTD in XHTML?

An XHTML DTD describes the allowed syntax and grammar of XHTML markup. Every XHTML document must start with a DTD declaration and a line of code that declares that you are starting to write XHTML code.


1 Answers

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 :)

like image 137
Jess Telford Avatar answered Sep 16 '22 22:09

Jess Telford