Function encodeHtml

  • Encodes the html passed in and converts it to a String so that it will not be interpreted as HTML by the browser. For example, if your input string was "<p>Hello</p>" the output would be "&lt;p&gt;Hello&lt;/p&gt;". If you set an element's innerHTML property to this string, the HTML markup will be displayed as literal text rather than being interpreted as HTML. By default this function will return an empty string if a value of undefined or null is passed it. To prevent this default, you can pass in a second optional parameter value of true to retain the empty value's type.

    Parameters

    • html: string

      The HTML to encode and return as a String value. If the value of this parameter is null or undefined, an empty string will be returned by default.

    • OptionalretainEmptyValueTypes: boolean

      Optional boolean parameter indicating that the empty values (null and undefined) should be returned as is from this function.

    Returns string

    The encoded HTML