SVGTextContentElement: getNumberOfChars() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.

getNumberOfChars()SVGTextContentElement インターフェイスのメソッドで、レンダリングされるかどうかに関わらず、現在の要素内でレンダリングできる利用できる文字の総数を表します。

構文

js
getNumberOfChars()

引数

なし。

返値

long 値です。

テキスト要素の文字数を数える

html
<svg width="300" height="100">
  <text id="exampleText" x="10" y="50">Hello, SVG World!</text>
</svg>
js
const textElement = document.getElementById("exampleText");

// テキスト要素内の文字数を取得する
const charCount = textElement.getNumberOfChars();

console.log(charCount); // 出力: 17

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGTextContentElement__getNumberOfChars

ブラウザーの互換性