My website is XHTML 1.1, and I had added 'rel' attributes to the <li>
and <div>
tags on my page, to store data for a jQuery script on the page. When validating my page, I get the error: "there is no attribute 'rel'". So, what is the best way to store arbitrary data in HTML tags?
I am working on a comments page for my website. When a comment is entered, it is POSTed via AJAX, which returns JSON of all comments. I then look at the 'rel' values to see which comments are already on the page, and only add the new ones.
The jQuery code works fine, it's just the 'rel' attributes don't validate.
HTML is designed with extensibility in mind for data that should be associated with a particular element but need not have any defined meaning. data-* attributes allow us to store extra information on standard, semantic HTML elements without other hacks such as non-standard attributes, or extra properties on DOM.
XHTML is an acronym for Extensible HyperText Markup Language. It is a subset of the Standard Generalized Markup Language (SGML) which is a system for organizing and defining parts of a document, like titles, or headings, or paragraphs, or images, through markup, also known as tagging.
td: To insert or add data in each cell, Table Data “td” tag is used.
While it's not XHTML spec, you could use the data-* attributes that are included in HTML5's spec.
http://html5doctor.com/html5-custom-data-attributes/
If you want to remain fully XHTML 1.1 compliant, you'll need to create a schema and include its namespace in the html
element, where the schema defines the attributes you want to use, and the elements to which they apply.
Extending XHTML
Since rel
isn't valid attribute for li
, you should use id
instead attribute instead and it is valid there too.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With