--- title: Node slug: Web/API/Node tags: - API - DOM - Interfaz - Nodo - Referencia translation_of: Web/API/Node ---
Node
es una interfaz en la cuál un número de objetos de tipo DOM API heredan. Esta interfaz permite que esos objetos sean tratados similarmente.
Las siguientes interfaces todas heredan de los metodos y propiedades de Node
: {{domxref("Document")}}, {{domxref("Element")}}, {{domxref("CharacterData")}} (heredan el {{domxref("Text")}}, el {{domxref("Comment")}}, y {{domxref("CDATASection")}}), {{domxref("ProcessingInstruction")}}, {{domxref("DocumentFragment")}}, {{domxref("DocumentType")}}, {{domxref("Notation")}}, {{domxref("Entity")}}, {{domxref("EntityReference")}}
Estas interfaces pueden retornar null en casos particulares donde los métodos y las propiedades no son relevantes. Pueden retornar una excepción - por ejemplo cuando se agregan hijos a un tipo de node del cuál no puede existir hijos.
herendan propiedades de sus padres {{domxref("EventTarget")}}.[1]
'/'
.Node
change, the {{domxref("NodeList")}} object is automatically updated.null
if the node has no child.null
if the node has no child.localName
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if it is no namespace. In Firefox 3.5 and earlier, HTML elements are in no namespace. In later versions, HTML elements are in the http://www.w3.org/1999/xhtml
namespace in both HTML and XML trees. {{ gecko_minversion_inline("1.9.2") }}namespaceURI
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if there isn't such node.Node
. The structure of the name will differ with the name type. E.g. An {{domxref("HTMLElement")}} will contain the name of the corresponding tag, like 'audio'
for an {{domxref("HTMLAudioElement")}}, a {{domxref("Text")}} node will have the '#text'
string, or a {{domxref("Document")}} node will have the '#document'
string.unsigned short
representing the type of the node. Possible values are:
Name | Value |
---|---|
ELEMENT_NODE |
1 |
ATTRIBUTE_NODE {{deprecated_inline()}} |
2 |
TEXT_NODE |
3 |
CDATA_SECTION_NODE {{deprecated_inline()}} |
4 |
ENTITY_REFERENCE_NODE {{deprecated_inline()}} |
5 |
ENTITY_NODE {{deprecated_inline()}} |
6 |
PROCESSING_INSTRUCTION_NODE |
7 |
COMMENT_NODE |
8 |
DOCUMENT_NODE |
9 |
DOCUMENT_TYPE_NODE |
10 |
DOCUMENT_FRAGMENT_NODE |
11 |
NOTATION_NODE {{deprecated_inline()}} |
12 |
Node
type, this returns null
and any set operation is ignored. For nodes of type TEXT_NODE
({{domxref("Text")}} objects), COMMENT_NODE
({{domxref("Comment")}} objects), and PROCESSING_INSTRUCTION_NODE
({{domxref("ProcessingInstruction")}} objects), the value corresponds to the text data contained in the object.null
.null
.null
.null
if no prefix is specified.prefix
to be defined on the {{domxref("Element")}} interface, Gecko-based browsers still implement it on the {{domxref("Node")}} interface.null
if there isn't such node.Inherits methods from its parents {{domxref("EventTarget")}}.[1]
Boolean
flag containing the result of a test whether the DOM implementation implements a specific feature and this feature is supported by the specific node.The following function recursively cycles all child nodes of a node and executes a callback function upon them (and upon the parent node itself).
function DOMComb (oParent, oCallback) { if (oParent.hasChildNodes()) { for (var oNode = oParent.firstChild; oNode; oNode = oNode.nextSibling) { DOMComb(oNode, oCallback); } } oCallback.call(oParent); }
DOMComb(parentNode, callbackFunction);
Recursively cycle all child nodes of parentNode
and parentNode
itself and execute the callbackFunction
upon them as this
objects.
parentNode
Node Object
).callbackFunction
Function
).The following example send to the console.log
the text content of the body:
function printContent () { if (this.nodeValue) { console.log(this.nodeValue); } } onload = function () { DOMComb(document.body, printContent); };
Element.prototype.removeAll = function () { while (this.firstChild) { this.removeChild(this.firstChild); } return this; };
/* ... an alternative to document.body.innerHTML = "" ... */ document.body.removeAll();
Specification | Status | Comment |
---|---|---|
{{SpecName('DOM WHATWG', '#interface-node', 'Node')}} | {{Spec2('DOM WHATWG')}} | Removed the following properties: attributes , namespaceURI , prefix , and localName .Removed the following methods: isSupported() , hasAttributes() , isSameNode() , getFeature() , setUserData() , and getUserData() . |
{{SpecName('DOM3 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM3 Core')}} | The methods insertBefore() , replaceChild() , removeChild() , and appendChild() returns one more kind of error (NOT_SUPPORTED_ERR ) if called on a {{domxref("Document")}}.The normalize() method has been modified so that {{domxref("Text")}} node can also be normalized if the proper {{domxref("DOMConfiguration")}} flag is set.Added the following methods: compareDocumentPosition() , isSameNode() , lookupPrefix() , isDefaultNamespace() , lookupNamespaceURI() , isEqualNode() , getFeature() , setUserData() , and getUserData(). Added the following properties: baseURI and textContent . |
{{SpecName('DOM2 Core', 'core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM2 Core')}} | The ownerDocument property was slightly modified so that {{domxref("DocumentFragment")}} also returns null .Added the following properties: namespaceURI , prefix , and localName .Added the following methods: normalize() , isSupported() and hasAttributes() . |
{{SpecName('DOM1', 'level-one-core.html#ID-1950641247', 'Node')}} | {{Spec2('DOM1')}} | Initial definition. |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoDesktop("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
getFeature() {{obsolete_inline}} |
{{CompatNo}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("6.0")}}. Removed in {{CompatGeckoDesktop("7.0")}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatNo}} |
getUserData() , setUserData() and hasAttributes() {{deprecated_inline}} |
{{CompatNo}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}. Removed in {{CompatGeckoDesktop("22.0")}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatNo}} |
isSameNode() {{obsolete_inline}} |
{{CompatNo}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("9.0")}}. Removed in {{CompatGeckoDesktop("10.0")}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatNo}} |
isSupported() {{obsolete_inline}} |
{{CompatUnknown}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}. Removed in {{CompatGeckoDesktop("22.0")}} |
{{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
attributes |
{{CompatNo}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("21.0")}}. Moved to {{domxref("Element")}} in {{CompatGeckoDesktop("22.0")}} |
{{CompatNo}} | {{CompatNo}} | {{CompatNo}} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatGeckoMobile("1.0")}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
getFeature() {{obsolete_inline}} |
{{CompatNo}} | Supported from {{CompatGeckoDesktop("1.0")}} to {{CompatGeckoDesktop("6.0")}}. Removed in {{CompatGeckoDesktop("7.0")}} |
{{CompatUnknown}} | {{CompatNo}} | {{CompatNo}} |
[1] Webkit and Blink incorrectly do not make Node
inherit from {{domxref("EventTarget")}}.