Dart API Referencedart:htmlText

Text class

In the DOM, the Text interface represents the textual content of an Element or Attr.  If an element has no markup within its content, it has a single child implementing Text that contains the element's text.  However, if the element contains markup, it is parsed into information items and Text nodes that form its children.

New documents have a single Text node for each block of text.  Over time, more Text nodes may be created as the document's content changes.  The Node.normalize() method merges adjacent Text objects back into a single node for each block of text.

Text also implements the CharacterData interface (which implements the Node interface).

@DomName('Text')
class Text extends CharacterData native "Text" {
 factory Text(String data) => document.$dom_createTextNode(data);

 @DomName('Text.wholeText')
 @DocsEditable
 final String wholeText;

 @DomName('Text.replaceWholeText')
 @DocsEditable
 // http://dom.spec.whatwg.org/#dom-text-replacewholetext
 @deprecated // deprecated
 Text replaceWholeText(String content) native;

 @DomName('Text.splitText')
 @DocsEditable
 Text splitText(int offset) native;


 @Creates('Null')  // Set from Dart code; does not instantiate a native type.
 StreamSubscription _textBinding;

 @Experimental
 void bind(String name, model, String path) {
   if (name != 'text') {
     super.bind(name, model, path);
     return;
   }

   unbind('text');

   _textBinding = new PathObserver(model, path).bindSync((value) {
     text = value == null ? '' : '$value';
   });
 }

 @Experimental
 void unbind(String name) {
   if (name != 'text') {
     super.unbind(name);
     return;
   }

   if (_textBinding == null) return;

   _textBinding.cancel();
   _textBinding = null;
 }

 @Experimental
 void unbindAll() {
   unbind('text');
   super.unbindAll();
 }
}

Extends

Interceptor > EventTarget > Node > CharacterData > Text

Subclasses

CDataSection

Constructors

factory Text(String data) #

factory Text(String data) => document.$dom_createTextNode(data);

Properties

final List<Node> $dom_childNodes #

inherited from Node
final List<Node> $dom_childNodes

final Node $dom_firstChild #

inherited from Node
final Node $dom_firstChild

final Node $dom_lastChild #

inherited from Node
final Node $dom_lastChild

final String $dom_localName #

inherited from Node
final String $dom_localName

final String $dom_namespaceUri #

inherited from Node
final String $dom_namespaceUri

String data #

inherited from CharacterData
String data

final Document document #

inherited from Node
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 int length #

inherited from CharacterData
final int length

final Element nextElementSibling #

inherited from CharacterData
final Element nextElementSibling

final Node nextNode #

inherited from Node
final Node nextNode

List<Node> nodes #

inherited from 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);
 }
}

final int nodeType #

inherited from Node
final int nodeType

final String nodeValue #

inherited from Node
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 #

inherited from Node
final Element parent

final Node parentNode #

inherited from Node
final Node parentNode

final Element previousElementSibling #

inherited from CharacterData
final Element previousElementSibling

final Node previousNode #

inherited from Node
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 #

inherited from Node

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

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

String text #

inherited from Node
String text

final String wholeText #

Returns all text of all Text nodes logically adjacent to this node, concatenated in document order.
final String wholeText

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) #

inherited from Node

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 appendData(String data) #

inherited from CharacterData
@DomName('CharacterData.appendData')
@DocsEditable
void appendData(String data) 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.

docs inherited from Node
@Experimental
void bind(String name, model, String path) {
 if (name != 'text') {
   super.bind(name, model, path);
   return;
 }

 unbind('text');

 _textBinding = new PathObserver(model, path).bindSync((value) {
   text = value == null ? '' : '$value';
 });
}

Node clone(bool deep) #

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

bool contains(Node other) #

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

void deleteData(int offset, int length) #

inherited from CharacterData
@DomName('CharacterData.deleteData')
@DocsEditable
void deleteData(int offset, int length) native;

bool dispatchEvent(Event event) #

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

bool hasChildNodes() #

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

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

inherited from Node

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) {
   _ChildNodeListLazy otherList = newNodes;
   if (identical(otherList._this, this)) {
     throw new ArgumentError(newNodes);
   }

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

Node insertBefore(Node newChild, Node refChild) #

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

void insertData(int offset, String data) #

inherited from CharacterData
@DomName('CharacterData.insertData')
@DocsEditable
void insertData(int offset, String data) 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() #

inherited from 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);
 }
}

void replaceData(int offset, int length, String data) #

inherited from CharacterData
@DomName('CharacterData.replaceData')
@DocsEditable
void replaceData(int offset, int length, String data) native;

Text replaceWholeText(String content) #

Replaces the text of the current node and all logically adjacent nodes with the specified text.
Note: Do not use this method as it has been removed from the standard and is no longer implemented in recent browsers, like Firefox 10.
@DomName('Text.replaceWholeText')
@DocsEditable
// http://dom.spec.whatwg.org/#dom-text-replacewholetext
@deprecated // deprecated
Text replaceWholeText(String content) native;

Node replaceWith(Node otherNode) #

inherited from Node

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;
}

Text splitText(int offset) #

Breaks the node into two nodes at a specified offset.
@DomName('Text.splitText')
@DocsEditable
Text splitText(int offset) native;

String substringData(int offset, int length) #

inherited from CharacterData
@DomName('CharacterData.substringData')
@DocsEditable
String substringData(int offset, int length) native;

String toString() #

inherited from Node

Print out a String representation of this Node.

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

void unbind(String name) #

Unbinds the attribute name.

docs inherited from Node
@Experimental
void unbind(String name) {
 if (name != 'text') {
   super.unbind(name);
   return;
 }

 if (_textBinding == null) return;

 _textBinding.cancel();
 _textBinding = null;
}

void unbindAll() #

Unbinds all bound attributes.

docs inherited from Node
@Experimental
void unbindAll() {
 unbind('text');
 super.unbindAll();
}

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

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

Node $dom_removeChild(Node oldChild) #

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

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

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

Node $dom_replaceChild(Node newChild, Node oldChild) #

inherited from Node
@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.