Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding data to XHTML tags

Tags:

html

xhtml

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.

like image 654
Rocket Hazmat Avatar asked Sep 08 '10 18:09

Rocket Hazmat


People also ask

Can we store extra information in an HTML tag?

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.

What are the XHTML tags?

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.

Which tag is used to add data in HTML?

td: To insert or add data in each cell, Table Data “td” tag is used.


2 Answers

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

like image 116
Jeff Meatball Yang Avatar answered Oct 16 '22 00:10

Jeff Meatball Yang


Since rel isn't valid attribute for li, you should use id instead attribute instead and it is valid there too.

like image 20
Sarfraz Avatar answered Oct 15 '22 23:10

Sarfraz