Similar to this SO question, I would like to use HTML nodes as keys in an object (not an array).
Example:
var _hotspots = {
[object HTMLDivElement] : { someProps:[1,2,3] },
[object HTMLDivElement] : { someProps:[1,2,3] }
}
and so I might achieve things like this:
for( var a in _hotspots ){
if(YAHOO.lang.hasOwnProperty(_hotspots, a)){
alert('key nodeName: '+a.nodeName);
}
}
So far, when I alert out ‘a’ above, it alerts out that it is in fact a [object HTMLDivElement], so it all seemed fine – but I can’t access properties on ‘a’, like nodeName.
Is what I am doing possible? Is it wrong? If I should be able to access properties on the object’s key reference then please let me know and I’ll write up a sample page.
cheers.
The keys of JavaScript objects are always character. You could store the id as the key and then retreive the element in your function.