Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

Text

BaselineWidely available *

TheText interface represents a textnode in a DOM tree.

EventTarget Node CharacterData Text

To understand what a text node is, consider the following document:

html
<html lang="en">  <head>    <title>Aliens?</title>  </head>  <body>    Why yes.  </body></html>

In that document, there are five text nodes, with the following contents:

  • "\n " (after the<head> start tag, a newline followed by four spaces)
  • "Aliens?" (the contents of thetitle element)
  • "\n " (after the</head> end tag, a newline followed by two spaces)
  • "\n " (after the<body> start tag, a newline followed by two spaces)
  • "\n Why yes.\n \n\n" (the contents of thebody element)

Each of those text nodes is an object that has the properties and methods documented in this article.

Constructor

Text()

Returns a newText node with the parameter as its textual content.

Instance properties

Inherits properties from its parents,CharacterData,Node, andEventTarget.

Text.assignedSlotRead only

Returns aHTMLSlotElement representing the<slot> the node is inserted in.

Text.wholeTextRead only

Returns a string containing the text of allText nodes logically adjacent to thisNode, concatenated in document order.

Instance methods

Inherits methods from its parent,CharacterData,Node, andEventTarget.

Text.splitText

Breaks the node into two nodes at a specified offset.

Specifications

Specification
DOM
# interface-text

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp