NamedNodeMap: phương thức removeNamedItem()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức removeNamedItem() của giao diện NamedNodeMap xóa Attr tương ứng với tên đã cho khỏi map.
Cú pháp
js
removeNamedItem(attrName)
Tham số
attrName-
Tên của thuộc tính cần xóa khỏi map.
Giá trị trả về
Attr đã bị xóa.
Ngoại lệ
NotFoundErrorDOMException-
Được ném nếu không có thuộc tính nào với tên đã cho.
Ví dụ
html
<pre test="testValue"></pre>
js
const pre = document.querySelector("pre");
const attrMap = pre.attributes;
let result = `The 'test' attribute initially contains '${attrMap["test"].value}'.\n`;
result += "We remove it.\n\n";
attrMap.removeNamedItem("test");
result += attrMap.getNamedItem("test")
? "And 'test' still exists."
: "And 'test' is no more to be found.";
pre.textContent = result;
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| DOM> # dom-namednodemap-removenameditem> |