W3C home > Mailing lists > Public > www-dom@w3.org > October to December 2000

Re: Hoo to add an attribute to a node?

From: Johnny Stenback <jst@netscape.com>
Date: Tue, 28 Nov 2000 01:56:24 -0800
Message-ID: <3A238148.102@netscape.com>
To: mario.heiss@gerling.de
CC: Gareth Reakes <gareth@decisionsoft.com>, www-dom@w3.org
Gareth Reakes wrote:

> Hello,
> 
> You can not append an attribute using appendChild(). It will cause a
> HIERARCHY_REQUEST_ERR. You should use setAttributeNode(). This applys only
> to element nodes so you may have to static_cast first.


Or simply do a node.setAttribute("name", "value") and let the 
implementation deal with creating the attribute node for you. 
setAttribute() will create a new attribute if the attribute you're 
setting doesn't exist and in at least some implementations using 
setAttribute() is even more efficient than creating the attribute and 
setting the attribute node on an element.

> 
> 
> Gareth
> 
> 
>>         if(attributes)
>>         {
>>           node.appendChild(myAttr); //add attribute to the node
>>         }
>> 
>> ....
>> 
>> Thanks in advance
>> Mario
>> 
>> 

-- 
jst
Received on Tuesday, 28 November 2000 04:56:30 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Friday, 22 June 2012 06:13:48 GMT