Re: Deprecated Attr methods

On Thu, May 21, 2015 at 8:01 PM, Matthew Phillips <matthew@bitovi.com> wrote:
> I just came across a warning for using a deprecated Attr method:
>
> https://developer.mozilla.org/en-US/docs/Web/API/Attr#Deprecated_properties_and_methods
>
> I'm using cloneNode() which is on the list. What is the workaround? Will I
> be able to do Node.prototype.cloneNode.call(attr) instead?

Hi Matthew,

This is related to a simplification of Attr that, if successful, would
result in Attr no longer inheriting from Node:
https://dom.spec.whatwg.org/#interface-attr

If that happens, Node.prototype.cloneNode.call(attr) wouldn't work
either, because attr would no longer be a Node, so it would throw an
exception.

Your best bet is to avoid Attr entirely, using getAttribute() and
setAttribute() instead. However, if for some reason you have an Attr
and want to set the same attribute on another element,
element2.setAttributeNS(attr.namespaceURI, attr.name, attr.value)
should do the trick.

Philip (does not work on Gecko, but pokes at Attr in Blink)

Received on Friday, 22 May 2015 12:15:22 UTC