By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,625 Members | 1,720 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,625 IT Pros & Developers. It's quick & easy.

Custom properties on DOM nodes

P: n/a
I try to associate DOM nodes with other objects. Assigning custom
properties to DOM nodes works in Firefox and Safari. It also works with
HTML nodes in IE6. However, it appears not to work with XML nodes that
are part of trees returned by XMLHttpRequest. How can I work around this
limitation? For XML nodes, I need to be able to associate at most one
object with each node.

The syntax I am using is
node.customproperty = value

--
Henri Sivonen
hs******@iki.fi
http://hsivonen.iki.fi/
Jul 23 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a


Henri Sivonen wrote:
I try to associate DOM nodes with other objects. Assigning custom
properties to DOM nodes works in Firefox and Safari. It also works with
HTML nodes in IE6. However, it appears not to work with XML nodes that
are part of trees returned by XMLHttpRequest.
Are you sure about XMLHttpRequest? That is implemented in Mozilla and in
Mozilla there is a common DOM for XML and HTML nodes so I am pretty sure
that at least Mozilla allows you to use an XML DOM node the same way as
an HTML DOM node where you could do
node.someProperty = expression;
The same for Opera 8.00 beta.
I am not sure about Safari and can't test while I am on Windows.
But I rather think IE is the one making problems as there XML DOM is not
integrated in the browser but provided by MSXML as ActiveX objects which
usually do not allow script to add custom properties.
How can I work around this
limitation? For XML nodes, I need to be able to associate at most one
object with each node.


You would need to do it the other way round, create your own wrapper
constructor function e.g.
function MyXmlNode (domNode) {
this.domNode = domNode;
}
then create wrapper objects where needed
var aNode = new MyXmlNode(someDomNode);
and add properties where needed:
aNode.someProperty = expression;
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 23 '05 #2

P: n/a
In article <42***********************@newsread2.arcor-online.net>,
Martin Honnen <ma*******@yahoo.de> wrote:
Henri Sivonen wrote:
I try to associate DOM nodes with other objects. Assigning custom
properties to DOM nodes works in Firefox and Safari. It also works with
HTML nodes in IE6. However, it appears not to work with XML nodes that
are part of trees returned by XMLHttpRequest.
Are you sure about XMLHttpRequest? That is implemented in Mozilla and in
Mozilla there is a common DOM for XML and HTML nodes so I am pretty sure
that at least Mozilla allows you to use an XML DOM node the same way as
an HTML DOM node where you could do
node.someProperty = expression;


I formulated my post badly. My point was that it does work on the XML
side in Mozilla and Safari but not in IE.

At least I think it works in Safari. Safari is broken in many ways and I
have not yet fully ported to Safari, but so far this particular feature
appears to work.
The same for Opera 8.00 beta.
Cool. I haven't even tested in Opera 8, yet, because the OS X beta
crashes on launch on my system.
But I rather think IE is the one making problems as there XML DOM is not
integrated in the browser but provided by MSXML as ActiveX objects which
usually do not allow script to add custom properties.


Right.
> How can I work around this
limitation? For XML nodes, I need to be able to associate at most one
object with each node.


You would need to do it the other way round, create your own wrapper
constructor function e.g.
function MyXmlNode (domNode) {
this.domNode = domNode;
}
then create wrapper objects where needed
var aNode = new MyXmlNode(someDomNode);
and add properties where needed:
aNode.someProperty = expression;


Thanks. That will get messy, because I will then have to support walking
the tree using the wrappers. :-(

--
Henri Sivonen
hs******@iki.fi
http://hsivonen.iki.fi/
Jul 23 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.