[ Web Proxy ]
URL:
Viewing: https://developer.mozilla.org/ko/docs/Web/API/Text/splitText [Back]  [Original]

Text.splitText() - Web API | MDN

This page was translated from English by the community. Learn more and join the MDN Web Docs community.

View in English Always switch to English

Text.splitText()

Baseline Widely available

This feature is well established and works across many devices and browser versions. Its been available across browsers since 2015 7.

Text.splitText() Text . sibling .

, , . . , sibling . , .

Node.normalize() .

16 INDEX_SIZE_ERR DOMException throw. NO_MODIFICATION_ALLOWED_ERR DOMException throw.

In this article

js
replacementNode = textnode.splitText(offset);

<p> <span> .

html
<body>
  <p id="p">foobar</p>

  <script type="text/javascript">
    var p = document.getElementById("p");
    var textnode = p.firstChild;

    // foo  bar  
    var replacementNode = textnode.splitText(3);

    // ' span contents '   span 
    var span = document.createElement("span");
    span.appendChild(document.createTextNode(" span contents "));

    // 'bar'  span 
    p.insertBefore(span, replacementNode);

    // : <p id="p">foo<span> span contents </span>bar</p>
  </script>
</body>

Specification
DOM
# ref-for-dom-text-splittext


Web Proxy Viewer  |  New URL  |  Original Page