back to Overview

_.escapeHtml()

Escapes all reserved characters for HTML so the string can be used in text or as attribute value.
Util module only.

Syntax

_.escapeHtml(s)

Parameters

s
the string to escape
(return value)
the escaped string

Description

Escapes all reserved characters for HTML so the string can be used in text or as attribute value. The escaped characters are '&', '<', '>', ''' (single quote) and '"' (double quote), and they will be escaped using char codes (e.g. '&#123;').

Example

Creating a HTML title

function createTitle(s) {
    return '<h1>' + _.escapeHtml(s) + '</h1>';
}

See also..

  • _.formatHtml() uses escapeHtml for escaping.
  • _.format() can use escapeHtml as escape function.
  • _.template() can use escapeHtml as escape function.

Comments

comments powered by Disqus

back to Overview

Functions