views:

303

answers:

2

Possible Duplicates:
Non-Standard Attributes on HTML Tags. Good Thing? Bad Thing? Your Thoughts?
Is there a generic attribute for all HTML elements aside from ID and class?

I have a series of divs that I would like to attatch extra info to. My idea was to use non-standard attributes to hold these values. Is this a bad idea, or against the W3C specs?

I was thinking something like:

<div children="0" parents="5">My title</div>

I see advantages to this, now I would like to find out what disadvantages there might be.

A: 

I have been reading jQuery in Action and it has a warning about using nonstandard attributes. Although common (per the book), your HTML will technically be invalid and could become inaccessible. It could also cause problems with programs that parse your site.

The author provided significantly better wording but I did not want to simply copy and paste the text.

Mayo
After testing this I would agree. Using jQuery, and trying to get the attribute which was not standard, returned: [object HTMLCollection]Since the children attribute is not in the HTMLCollection object it can't return what I added to that fake attribute.I won't use it. Case closed. :)
Nic Hubbard
I've since closed the book, but if I recall the author was demonstrating how to access custom attributes from jQuery. He was merely warning that it came with some baggage. :)
Mayo
A: 

You should always be very careful about using non-standard stuff like this. In a perfect world you would never do something like that. But since the www is far from perfect somtimes you hardly have a choice.

Doing something like this should only be a last resort. If there is any other way of doing it that conforms to the standards, choose that option.

If nothing else there is one argument that should be a killer: By doing something like this you most likely are making the job of ensuring that the site/application works in as many browsers as possible harder.

Finally, following standards is always a good habit :)

deadcyclo