Let's say I'm generating markup through server-side code. I'm generating a bunch of HTML tags but I want to add custom attributes (properties).
In JavaScript (if I had a reference to the DOM node I could write):
var myDOMNode = ...
myDOMNode.myCustomAttribute = "Hi!";
The issue here is that I don't want to qualify every element with an unique id just to initialize data.
If I'm remembing this correctly, this is valid IE stuff.
<div onload="this.myCustomAttribute='Hi!'"></div>
If I added an event handler on that element I should be able to access it's "data context" though the identifier 'myCustomAttribute', which is really what I want.
If anyone has a neat trick to make this happen, I'm all ears.
EDIT:
I don't want to go against W3C recommendations or re-purpose attributes in a hackish way and I don't want to depend on IE only stuff.
@AnthonyWJones, a technique I usually go about using is that I tag DOMElements with data when working with JavaScript. To the extent of my knowledge it's perfectly OK to say that even though the property is undefined I can set a property on any object and refer to that later.
var myObj = ...
alert(myObj.someProperty); // undefined
myObj.someProperty = "Hi!";
alert(myObj["someProperty"]); // Hi!
Objects in JavaScript are just name/value dictionaries. When I wrote that attribute thing, this is what I meant. Sorry for that.
It really bothers me that the only purpose these id="" attributes will have is to initialize this data.
For the record, I could be going about this the wrong way but I really want to pursue this idea a bit more, because it's appealing to me.