setAttributeNS
Sets or removes a namespaced attribute such as xlink:href or xml:lang, with the value rules and the URL check of setAttribute.
Sets or removes a namespaced attribute such as xlink:href or xml:lang, with the value rules
and the URL check of setAttribute. Removal uses the local part of the name (href for
xlink:href).
Import#
ts
import { setAttributeNS } from "@shadow-js/web";
Signature#
ts
function setAttributeNS(el: Element, namespace: string, name: string, value: unknown): void
Parameters#
| Name | Description |
|---|---|
el |
Target element. |
namespace |
Namespace URI. "" means no namespace, which behaves exactly like setAttribute. |
name |
Qualified name (prefix:local). It must match [A-Za-z_:][A-Za-z0-9_:.-]*. |
value |
The value, with the same rules as setAttribute. |
Throws#
- TypeError
INVALID_ATTRIBUTE_NAMEwhennameis not a valid attribute name.
Examples#
ts
import { setAttributeNS } from "@shadow-js/web";
const XLINK = "http://www.w3.org/1999/xlink";
const use = document.createElementNS("http://www.w3.org/2000/svg", "use");
setAttributeNS(use, XLINK, "xlink:href", "#icon-star");
setAttributeNS(use, XLINK, "xlink:href", null); // removes it