Skip to content

UseSetAttribute

katanakit-js / useSetAttribute

function useSetAttribute(
target,
attr,
value
): void;

Defined in: infrastructure/dom/dom.service.ts:250

Sets an attribute on the target element with XSS protection. Blocks event-handler attributes (on*) and javascript: URLs.

Parameter Type Description
target string | Element A CSS selector string or an Element instance.
attr string The attribute name.
value string The value to set.

void

If the attribute is an event handler or contains a javascript: URL.

useSetAttribute("img.hero", "src", "/photo.jpg");
useSetAttribute("a.link", "href", "https://example.com");