Dart API Referencedart:htmlNode

Node class

A Node is an interface from which a number of DOM types inherit, and allows these various types to be treated (or tested) similarly.
The following all inherit this interface and its methods and properties (though they may return null in particular cases where not relevant; or throw an exception when adding children to a node type for which no children can exist): Document , Element , Attr , CharacterData (which Text , Comment , and CDATASection inherit), ProcessingInstruction , DocumentFragment , DocumentType , Notation , Entity , EntityReference
@DomName('Node')
class Node extends EventTarget native "Node" {
 List<Node> get nodes {
   return new _ChildNodeListLazy(this);
 }

 void set nodes(Iterable<Node> value) {
   // Copy list first since we don't want liveness during iteration.
   // TODO(jacobr): there is a better way to do this.
   List copy = new List.from(value);
   text = '';
   for (Node node in copy) {
     append(node);
   }
 }

 /**
  * Removes this node from the DOM.
  */
 @DomName('Node.removeChild')
 void remove() {
   // TODO(jacobr): should we throw an exception if parent is already null?
   // TODO(vsm): Use the native remove when available.
   if (this.parentNode != null) {
     final Node parent = this.parentNode;
     parentNode.$dom_removeChild(this);
   }
 }

 /**
  * Replaces this node with another node.
  */
 @DomName('Node.replaceChild')
 Node replaceWith(Node otherNode) {
   try {
     final Node parent = this.parentNode;
     parent.$dom_replaceChild(otherNode, this);
   } catch (e) {

   };
   return this;
 }

 /**
  * Inserts all of the nodes into this node directly before refChild.
  *
  * See also:
  *
  * * [insertBefore]
  */
 Node insertAllBefore(Iterable<Node> newNodes, Node refChild) {
   if (newNodes is _ChildNodeListLazy) {
     if (identical(newNodes._this, this)) {
       throw new ArgumentError(newNodes);
     }

     // Optimized route for copying between nodes.
     for (var i = 0, len = newNodes.length; i < len; ++i) {
       // Should use $dom_firstChild, Bug 8886.
       this.insertBefore(newNodes[0], refChild);
     }
   } else {
     for (var node in newNodes) {
       this.insertBefore(node, refChild);
     }
   }
 }

 /**
  * Print out a String representation of this Node.
  */
 String toString() => localName == null ?
     (nodeValue == null ? super.toString() : nodeValue) : localName;

 /**
  * Binds the attribute [name] to the [path] of the [model].
  * Path is a String of accessors such as `foo.bar.baz`.
  */
 @Experimental
 void bind(String name, model, String path) {
   // TODO(jmesserly): should we throw instead?
   window.console.error('Unhandled binding to Node: '
       '$this $name $model $path');
 }

 /** Unbinds the attribute [name]. */
 @Experimental
 void unbind(String name) {}

 /** Unbinds all bound attributes. */
 @Experimental
 void unbindAll() {}

 TemplateInstance _templateInstance;

 /** Gets the template instance that instantiated this node, if any. */
 @Experimental
 TemplateInstance get templateInstance =>
     _templateInstance != null ? _templateInstance :
     (parent != null ? parent.templateInstance : null);


 @DomName('Node.ATTRIBUTE_NODE')
 @DocsEditable
 static const int ATTRIBUTE_NODE = 2;

 @DomName('Node.CDATA_SECTION_NODE')
 @DocsEditable
 static const int CDATA_SECTION_NODE = 4;

 @DomName('Node.COMMENT_NODE')
 @DocsEditable
 static const int COMMENT_NODE = 8;

 @DomName('Node.DOCUMENT_FRAGMENT_NODE')
 @DocsEditable
 static const int DOCUMENT_FRAGMENT_NODE = 11;

 @DomName('Node.DOCUMENT_NODE')
 @DocsEditable
 static const int DOCUMENT_NODE = 9;

 @DomName('Node.DOCUMENT_TYPE_NODE')
 @DocsEditable
 static const int DOCUMENT_TYPE_NODE = 10;

 @DomName('Node.ELEMENT_NODE')
 @DocsEditable
 static const int ELEMENT_NODE = 1;

 @DomName('Node.ENTITY_NODE')
 @DocsEditable
 static const int ENTITY_NODE = 6;

 @DomName('Node.ENTITY_REFERENCE_NODE')
 @DocsEditable
 static const int ENTITY_REFERENCE_NODE = 5;

 @DomName('Node.NOTATION_NODE')
 @DocsEditable
 static const int NOTATION_NODE = 12;

 @DomName('Node.PROCESSING_INSTRUCTION_NODE')
 @DocsEditable
 static const int PROCESSING_INSTRUCTION_NODE = 7;

 @DomName('Node.TEXT_NODE')
 @DocsEditable
 static const int TEXT_NODE = 3;

 @JSName('childNodes')
 @DomName('Node.childNodes')
 @DocsEditable
 @Returns('NodeList')
 @Creates('NodeList')
 final List<Node> $dom_childNodes;

 @JSName('firstChild')
 @DomName('Node.firstChild')
 @DocsEditable
 final Node $dom_firstChild;

 @JSName('lastChild')
 @DomName('Node.lastChild')
 @DocsEditable
 final Node $dom_lastChild;

 @DomName('Node.localName')
 @DocsEditable
 final String localName;

 @JSName('namespaceURI')
 @DomName('Node.namespaceURI')
 @DocsEditable
 final String $dom_namespaceUri;

 @JSName('nextSibling')
 @DomName('Node.nextSibling')
 @DocsEditable
 final Node nextNode;

 @DomName('Node.nodeType')
 @DocsEditable
 final int nodeType;

 @DomName('Node.nodeValue')
 @DocsEditable
 final String nodeValue;

 @JSName('ownerDocument')
 @DomName('Node.ownerDocument')
 @DocsEditable
 final Document document;

 @JSName('parentElement')
 @DomName('Node.parentElement')
 @DocsEditable
 final Element parent;

 @DomName('Node.parentNode')
 @DocsEditable
 final Node parentNode;

 @JSName('previousSibling')
 @DomName('Node.previousSibling')
 @DocsEditable
 final Node previousNode;

 @JSName('textContent')
 @DomName('Node.textContent')
 @DocsEditable
 String text;

 @JSName('addEventListener')
 @DomName('Node.addEventListener')
 @DocsEditable
 void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) native;

 @JSName('appendChild')
 /**
  * Adds a node to the end of the child [nodes] list of this node.
  *
  * If the node already exists in this document, it will be removed from its
  * current parent node, then added to this node.
  *
  * This method is more efficient than `nodes.add`, and is the preferred
  * way of appending a child node.
  */
 @DomName('Node.appendChild')
 @DocsEditable
 Node append(Node newChild) native;

 @JSName('cloneNode')
 @DomName('Node.cloneNode')
 @DocsEditable
 Node clone(bool deep) native;

 @DomName('Node.contains')
 @DocsEditable
 bool contains(Node other) native;

 @DomName('Node.dispatchEvent')
 @DocsEditable
 bool dispatchEvent(Event event) native;

 @DomName('Node.hasChildNodes')
 @DocsEditable
 bool hasChildNodes() native;

 @DomName('Node.insertBefore')
 @DocsEditable
 Node insertBefore(Node newChild, Node refChild) native;

 @JSName('removeChild')
 @DomName('Node.removeChild')
 @DocsEditable
 Node $dom_removeChild(Node oldChild) native;

 @JSName('removeEventListener')
 @DomName('Node.removeEventListener')
 @DocsEditable
 void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) native;

 @JSName('replaceChild')
 @DomName('Node.replaceChild')
 @DocsEditable
 Node $dom_replaceChild(Node newChild, Node oldChild) native;

}

Extends

Interceptor > EventTarget > Node

Subclasses

Attr, CharacterData, Document, DocumentFragment, DocumentType, Element, Notation, ProcessingInstruction

Static Properties

const int ATTRIBUTE_NODE #

static const int ATTRIBUTE_NODE = 2

const int CDATA_SECTION_NODE #

static const int CDATA_SECTION_NODE = 4

const int COMMENT_NODE #

static const int COMMENT_NODE = 8

const int DOCUMENT_FRAGMENT_NODE #

static const int DOCUMENT_FRAGMENT_NODE = 11

const int DOCUMENT_NODE #

static const int DOCUMENT_NODE = 9

const int DOCUMENT_TYPE_NODE #

static const int DOCUMENT_TYPE_NODE = 10

const int ELEMENT_NODE #

static const int ELEMENT_NODE = 1

const int ENTITY_NODE #

static const int ENTITY_NODE = 6

const int ENTITY_REFERENCE_NODE #

static const int ENTITY_REFERENCE_NODE = 5

const int NOTATION_NODE #

static const int NOTATION_NODE = 12

const int PROCESSING_INSTRUCTION_NODE #

static const int PROCESSING_INSTRUCTION_NODE = 7

const int TEXT_NODE #

static const int TEXT_NODE = 3

Properties

final List<Node> $dom_childNodes #

final List<Node> $dom_childNodes

final Node $dom_firstChild #

final Node $dom_firstChild

final Node $dom_lastChild #

final Node $dom_lastChild

final String $dom_namespaceUri #

final String $dom_namespaceUri

final Document document #

final Document document

final int hashCode #

inherited from Interceptor

Get a hash code for this object.

All objects have hash codes. Hash codes are guaranteed to be the same for objects that are equal when compared using the equality operator ==. Other than that there are no guarantees about the hash codes. They will not be consistent between runs and there are no distribution guarantees.

If a subclass overrides hashCode it should override the equality operator as well to maintain consistency.

docs inherited from Object
int get hashCode => Primitives.objectHashCode(this);

final String localName #

final String localName

final Node nextNode #

final Node nextNode

List<Node> nodes #

List<Node> get nodes {
 return new _ChildNodeListLazy(this);
}
void set nodes(Iterable<Node> value) {
 // Copy list first since we don't want liveness during iteration.
 // TODO(jacobr): there is a better way to do this.
 List copy = new List.from(value);
 text = '';
 for (Node node in copy) {
   append(node);
 }
}

final int nodeType #

final int nodeType

final String nodeValue #

final String nodeValue

final Events on #

inherited from EventTarget

This is an ease-of-use accessor for event streams which should only be used when an explicit accessor is not available.

Events get on => new Events(this);

final Element parent #

final Element parent

final Node parentNode #

final Node parentNode

final Node previousNode #

final Node previousNode

final Type runtimeType #

inherited from Interceptor

A representation of the runtime type of the object.

docs inherited from Object
Type get runtimeType => getRuntimeType(this);

final TemplateInstance templateInstance #

Gets the template instance that instantiated this node, if any.

@Experimental
TemplateInstance get templateInstance =>
   _templateInstance != null ? _templateInstance :
   (parent != null ? parent.templateInstance : null);

String text #

String text

Operators

bool operator ==(other) #

inherited from Interceptor

The equality operator.

The default behavior for all Objects is to return true if and only if this and other are the same object.

If a subclass overrides the equality operator it should override the hashCode method as well to maintain consistency.

docs inherited from Object
bool operator ==(other) => identical(this, other);

Methods

Node append(Node newChild) #

Adds a node to the end of the child nodes list of this node.

If the node already exists in this document, it will be removed from its current parent node, then added to this node.

This method is more efficient than nodes.add, and is the preferred way of appending a child node.

@JSName('appendChild')
/**
* Adds a node to the end of the child [nodes] list of this node.
*
* If the node already exists in this document, it will be removed from its
* current parent node, then added to this node.
*
* This method is more efficient than `nodes.add`, and is the preferred
* way of appending a child node.
*/
@DomName('Node.appendChild')
@DocsEditable
Node append(Node newChild) native;

void bind(String name, model, String path) #

Binds the attribute name to the path of the model. Path is a String of accessors such as foo.bar.baz.

@Experimental
void bind(String name, model, String path) {
 // TODO(jmesserly): should we throw instead?
 window.console.error('Unhandled binding to Node: '
     '$this $name $model $path');
}

Node clone(bool deep) #

@JSName('cloneNode')
@DomName('Node.cloneNode')
@DocsEditable
Node clone(bool deep) native;

bool contains(Node other) #

@DomName('Node.contains')
@DocsEditable
bool contains(Node other) native;

bool dispatchEvent(Event event) #

@DomName('Node.dispatchEvent')
@DocsEditable
bool dispatchEvent(Event event) native;

bool hasChildNodes() #

@DomName('Node.hasChildNodes')
@DocsEditable
bool hasChildNodes() native;

Node insertAllBefore(Iterable<Node> newNodes, Node refChild) #

Inserts all of the nodes into this node directly before refChild.

See also:

Node insertAllBefore(Iterable<Node> newNodes, Node refChild) {
 if (newNodes is _ChildNodeListLazy) {
   if (identical(newNodes._this, this)) {
     throw new ArgumentError(newNodes);
   }

   // Optimized route for copying between nodes.
   for (var i = 0, len = newNodes.length; i < len; ++i) {
     // Should use $dom_firstChild, Bug 8886.
     this.insertBefore(newNodes[0], refChild);
   }
 } else {
   for (var node in newNodes) {
     this.insertBefore(node, refChild);
   }
 }
}

Node insertBefore(Node newChild, Node refChild) #

@DomName('Node.insertBefore')
@DocsEditable
Node insertBefore(Node newChild, Node refChild) native;

dynamic noSuchMethod(Invocation invocation) #

inherited from Interceptor

noSuchMethod is invoked when users invoke a non-existant method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.

The default behavior of noSuchMethod is to throw a noSuchMethodError.

docs inherited from Object
dynamic noSuchMethod(Invocation invocation) {
 throw new NoSuchMethodError(
     this,
     _symbolToString(invocation.memberName),
     invocation.positionalArguments,
     _symbolMapToStringMap(invocation.namedArguments));
}

void remove() #

Removes this node from the DOM.

@DomName('Node.removeChild')
void remove() {
 // TODO(jacobr): should we throw an exception if parent is already null?
 // TODO(vsm): Use the native remove when available.
 if (this.parentNode != null) {
   final Node parent = this.parentNode;
   parentNode.$dom_removeChild(this);
 }
}

Node replaceWith(Node otherNode) #

Replaces this node with another node.

@DomName('Node.replaceChild')
Node replaceWith(Node otherNode) {
 try {
   final Node parent = this.parentNode;
   parent.$dom_replaceChild(otherNode, this);
 } catch (e) {

 };
 return this;
}

String toString() #

Print out a String representation of this Node.

String toString() => localName == null ?
   (nodeValue == null ? super.toString() : nodeValue) : localName;

void unbind(String name) #

Unbinds the attribute name.

@Experimental
void unbind(String name) {}

void unbindAll() #

Unbinds all bound attributes.

@Experimental
void unbindAll() {}

void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) #

@JSName('addEventListener')
@DomName('Node.addEventListener')
@DocsEditable
void $dom_addEventListener(String type, EventListener listener, [bool useCapture]) native;

Node $dom_removeChild(Node oldChild) #

@JSName('removeChild')
@DomName('Node.removeChild')
@DocsEditable
Node $dom_removeChild(Node oldChild) native;

void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) #

@JSName('removeEventListener')
@DomName('Node.removeEventListener')
@DocsEditable
void $dom_removeEventListener(String type, EventListener listener, [bool useCapture]) native;

Node $dom_replaceChild(Node newChild, Node oldChild) #

@JSName('replaceChild')
@DomName('Node.replaceChild')
@DocsEditable
Node $dom_replaceChild(Node newChild, Node oldChild) native;

This page includes content from the Mozilla Foundation that is graciously licensed under a Creative Commons: Attribution-Sharealike license. Mozilla has no other association with Dart or dartlang.org. We encourage you to improve the web by contributing to The Mozilla Developer Network.