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

Text: splitText() - Web API | MDN

MDN Web Docs

View in English Always switch to English

Text: splitText()

Baseline

20157

splitText() Text Text 2

Node.normalize()

js
newNode = textNode.splitText(offset)

offset

Text

IndexSizeError DOMException

16

NoModificationAllowedError DOMException

<p> 2 <u>

html
<p>foobar</p>
js
const p = document.querySelector("p");

// <p> 
const foobar = p.firstChild;

// 'foobar'  'foo'  'bar' 
// 'bar'  const 
const bar = foobar.splitText(3);

// <u>  ' new content ' 
const u = document.createElement("u");
u.appendChild(document.createTextNode(" new content "));

// <u>  'bar' 
p.insertBefore(u, bar);

// : <p>foo<u> new content </u>bar</p>

DOM
# ref-for-dom-text-splittext


Web Proxy Viewer  |  New URL  |  Original Page