Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to add non standard attributes to DOM elements? - HTML/Javascript [duplicate]

Possible Duplicate:
Is it considered bad practice to use non-standard HTML attributes?

Hi folks,

I'm building a javascript library, the idea of which is to add functionality to various elements on page.

Easiest way for complete isolation would be to add a non standard attribute

e.g. <div special="true" >...</div>

Other alternatives are classes and onclick javascript.


Any ideas?

like image 690
RadiantHex Avatar asked Feb 05 '11 20:02

RadiantHex


2 Answers

HTML5 supports "data" type attributes, but in general for a modern day site, this would cause most sites to fail validation if they are going for any doctype other than HTML5.

So that would just be adding a barrier to entry for potential users of your library.

like image 164
jondavidjohn Avatar answered Oct 31 '22 23:10

jondavidjohn


Don't do it. I've learned the hard way that this is not cross-browser. I had a jQuery-intensive app totally fail to function in Chrome because of this.

like image 44
anon Avatar answered Oct 31 '22 23:10

anon