{hero}

DataTable.util.stripHtml()

Since: DataTables 2.0

Remove HTML from a string.

Description

DataTables and its extensions often need to strip out HTML from string based data - e.g. for ordering and search in the table. This method exposes a utility function to do that. It is quite simple in that it removes any content between < and >, and incomplete script tags (<script).

This simple form is chosen for performance and meeting the requirements of most use cases. However, there are circumstances whereby you might need a more complex HTML stripper - e.g. with nested HTML in attributes. For such cases this function can be used as a setter to give DataTables a function that it should use for stripping HTML. If used this way, the stripping function should accept a single parameter and return a sanitized string.

Types

function stripHtml( str )

Description:

Remove mark up from a string.

Returns:

Sanitized string

function stripHtml( fn )

Description:

Set the HTML stripping function.

Example

Strip HTML from a string:

let sanitized = DataTable.util.stripHtml('<a href="...">Link</a>');

// sanitized is: 'Link'