Since: DataTables 2.0

Remove HTML from a string.


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.


function stripHtml( str )


Remove mark up from a string.


Sanitized string

function stripHtml( fn )


Set the HTML stripping function.


Strip HTML from a string:

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

// sanitized is: 'Link'