NamedNodeMap: removeNamedItemNS() 方法

Baseline 已廣泛支援

此特性已相當成熟,可在許多裝置和瀏覽器版本上使用。自 ⁨2015 年 7 月⁩以來,各瀏覽器均已提供此特性。

NamedNodeMap 介面的 removeNamedItemNS() 方法會從對映中移除具有給定名稱空間和本地名稱的 Attr 節點。

語法

js
removeNamedItemNS(namespace, localName)

引數

namespace

要從對映中移除的屬性的名稱空間

警告:namespace 是名稱空間的 URI,而不是字首。

localName

要從對映中移除的屬性的本地名稱。

返回值

被移除的 Attr 節點。

異常

NotFoundError DOMException

如果沒有具有給定名稱空間和本地名稱的屬性,則會丟擲此異常。

示例

js
const parser = new DOMParser();
const xmlString =
  '<warning ob:one="test" xmlns:ob="http://www.example.com/ob">Beware!</warning>';
const doc = parser.parseFromString(xmlString, "application/xml");

const pre = document.querySelector("pre");
const warning = doc.querySelector("warning");
const attrMap = warning.attributes;

let result = `The 'ob:one' attribute initially contains '${attrMap["ob:one"].value}'.\n`;

result += "We remove it.\n\n";
attrMap.removeNamedItemNS("http://www.example.com/ob", "one");

result += attrMap["ob:one"]
  ? "And 'ob:one' still exists."
  : "And 'ob:one' is no more to be found.";

pre.textContent = result;

規範

規範
DOM
# dom-namednodemap-removenameditemns

瀏覽器相容性