DOM4: Deprecated properties and methods, what does this mean?

"Warning: In DOM Core 1, 2 and 3, Attr is inherited from Node. This is no longer the case with DOM4. To bring the implementation of Attr to the specification, work is underway to change it. It is no longer inherited from Node. You should not use any properties or Node methods for Attr objects. Starting with Gecko 7.0 (Firefox 7.0 / Thunderbird 7.0 / SeaMonkey 2.4), those that are deleted will display warning messages to the console. You should revise your code accordingly. See " Deprecated properties and methods for a complete list. "

Scrolling through the page, we can see the replacements for nodeName and NodeValue, using Attr.name and Attr.value.

https://developer.mozilla.org/en/DOM/Attr#Deprecated_properties_and_methods

What does this mean for other methods like attributes or childNodes? The link says that it is out of date, but they do not give any replacement!

This is deprecated for the attribute, but is it also for Node?

Attr Object: http://www.w3schools.com/jsref/dom_obj_attr.asp

Edit: nodeValue will ONLY be deprecated for attributes (Attr), since Attr will not inherit from Node anymore in DOM Level 4:

Here is a quick example that helped me understand:

<div id="myAttribute">myTextNode</div> var myDiv = document.getElementById("myAttribute"); // If you want to get "myAttribute" from div tag alert(myDiv.attributes[0].value); // Correct way to get value of an attribute (displays "myAttribute") alert(myDiv.attributes[0].nodeValue); // Working too but deprecated method for Attr since it doesn't inherit from Node in DOM4 (.nodeValue is specific to a Node, not an Attribute) // If you want to get "myTextNode" from div tag alert(myDiv.childNodes[0].value); // Not working since .value is specific to an attribute, not a Node (displays "undefined") alert(myDiv.childNodes[0].nodeValue); // Working, .nodeValue is the correct way to get the value of a Node, it will not be deprecated for Nodes! (displays "myTextNode") 

Perhaps this will avoid confusion with others when accessing attributes / nodes :)

+7
source share
1 answer

What they say are objects that were instances of Attr (for example, those that were returned by Element.getAttributeNode() ), the properties used, which he inherited from Node .

However, since this is not the case in DOM4, they are trying to remove this inheritance. Because of this, when you now get an instance of the Attr object, the properties listed in the deprecated list will behave as they are documented,

The big question is: It is deprecated for the attribute, but is it also for Node? : No, they are not outdated. You can see the list of Node properties from its own documentation page.

Attr objects are not used anyway (ever?); Are you sure this concerns you?

+6
source

All Articles