このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

SVGTransformList: removeItem() メソッド

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨2015年7月⁩.

removeItem()SVGTransformList インターフェイスのメソッドで、指定された位置にある既存のアイテムをリストから除去します。

構文

js
removeItem(index)

引数

index

integer 除去するアイテムのインデックスを unsigned long で表します。

返値

SVGTransform オブジェクトです。リストから除去されたアイテムです。

例外

このメソッドは、次の型の DOMException を発生させる可能性があります。

NoModificationAllowedError DOMException

SVGTransformList が読み取り専用属性に対応する場合、またはオブジェクト自体が読み取り専用である場合に発生します。

IndexSizeError DOMException

インデックス番号が numberOfItems 以上であった場合に発生します。

リストから座標変換を削除

html
<svg width="200" height="200" id="mySvg">
  <rect
    width="100"
    height="100"
    fill="blue"
    transform="translate(50,50) rotate(45)" />
</svg>
js
const svgElement = document.querySelector("svg");
const rectElement = svgElement.querySelector("rect");

// <rect> 要素の座標変換リストへのアクセス
const transformList = rectElement.transform.baseVal;

const removedTransform = transformList.removeItem(0);
console.dir(removedTransform); // 出力: SVGTransform { type: 2, matrix: SVGMatrix, angle: 0 }

// 更新されたリストの長さ
console.log(`更新後の座標変換の数: ${transformList.length}`); // 出力: 1

仕様書

Specification
Scalable Vector Graphics (SVG) 2
# __svg__SVGNameList__removeItem

ブラウザーの互換性

関連情報