Non- (X) HTML attributes ... any flaws?

I usually tried to use DOM attributes only when writing Javascript. Now that I have switched from Prototype to jQuery, I can get some serious mileage from adding my own attributes to the various DOM elements, mainly because you can set up a very readable coding convention to handle AJAX requests.

As a brief example, this means that I am doing things like

<div type="book" app_id="13"> <a href="#" action="delete">delete</a> </div> 

And then I can configure the code to find all the <a> tags with the action attribute, find the parent with type and app_id , and then do the CRUD operations ... all without me, to write extra code.

Are there any pitfalls (with the exception of not strictly XHTML complaints) that I should follow, and / or any good habits that I should look for to follow? What about the standard way to configure my own attribute namespace?

+6
jquery html xml namespaces xhtml
source share
4 answers

Can I store user attributes in an HTML DOM, like a record in a database?

The new HTML 5 data attributes may be what you are looking for.

http://ejohn.org/blog/html-5-data-attributes/

http://dev.w3.org/html5/spec/Overview.html#custom

I know this is not "XHTML", but at least it is part of some standard;)

+4
source share

In accordance with this question, the use of XML namespaces in XHTML 1.0 is not allowed. Adding your own attributes to the same namespace seems to me worse, since they are certainly invalid, even with regard to XML.

If I did this, I would get my mileage from the class and rel attributes. For example:

 <div class="book" id="book_13"> <a href="http://example.com/url/to/delete/non/ajaxily" class="delete">delete</a> </div> 
+6
source share

I do not see anything wrong with this approach. In fact, I saw many examples of this, and I myself used this approach in many applications and did not encounter any obstacles other than this check. Therefore, I think that you are free: =)

0
source share

I see nothing wrong with adding invalid attributes unless someone uses some unknown browser that is super strict and fails in everything that is not standard. It may happen, I suppose ... but it is doubtful ...

One good alternative would be to use jQuery Metadata Plugin to store easily accessible key-> value pairs from an attribute.

0
source share

All Articles