UseSetAttribute
katanakit-js / useSetAttribute
Function: useSetAttribute()
Section titled “Function: 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.
Parameters
Section titled “Parameters”| 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. |
Returns
Section titled “Returns”void
Throws
Section titled “Throws”If the attribute is an event handler or contains a javascript: URL.
Example
Section titled “Example”useSetAttribute("img.hero", "src", "/photo.jpg");useSetAttribute("a.link", "href", "https://example.com");