W3C home > Mailing lists > Public > public-html@w3.org > May 2015

Re: Deprecated Attr methods

From: Philip Jägenstedt <philipj@opera.com>
Date: Fri, 22 May 2015 14:14:54 +0200
Message-ID: <CAMQvoCkpQSMUR23G+pqB+Lwj308VJYWh4+i7wJjaRTCrre6aQA@mail.gmail.com>
To: Matthew Phillips <matthew@bitovi.com>
Cc: public-html <public-html@w3.org>
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

This archive was generated by hypermail 2.4.0 : Saturday, 9 October 2021 18:46:13 UTC