Vote count:
0
I would like to store an object in Javascript in a custom attribute of a DOM node. I've tried setAttribute/getAttribute, but they convert the attribute into text.
Assume I've already done
node = document.getElementById( 'SAMPLE' );
object = { test: function( ){ stuff; } };
This doesn't work anywhere I've tested
node.setAttribute( 'info', object );
val = node.getAttribute( 'info' ) ;
because it leaves val with a string value.
If I do
node[ 'info' ] = object;
then
val = node[ 'info' ];
gives me back my object later in my script.
Will this work in pre-HTML5 browsers like old IEs? Is it safe?
asked 35 secs ago
Can I store a non-text property in a DOM node in Javascript
Aucun commentaire:
Enregistrer un commentaire