Sanitizer: setDataAttributes() method

Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.

The setDataAttributes() method of the Sanitizer interface sets whether data attributes will be allowed or removed by the sanitizer.

The method sets the dataAttributes property in this sanitizer's configuration.

Syntax

js
setDataAttributes(allow);

Parameters

allow

true if data attributes are allowed, and false if they are to be removed.

Returns

None (undefined).

Examples

How to sanitize data attributes

The code below shows the basic usage of the setDataAttributes() method.

js
// Create sanitizer (in this case the default)
const sanitizer = new Sanitizer();

// Allow data attributes
sanitizer.setDataAttributes(true);

// Remove data attributes
sanitizer.setDataAttributes(false);

Specifications

Specification
HTML Sanitizer API
# dom-sanitizer-setdataattributes

Browser compatibility