Certain characters have special significance in HTML, and should be represented by HTML entities if they are to preserve their meanings. This function returns a string with some of these conversions made.
This function makes following replacements:
| Original | Replaced character |
|---|---|
| & (ampersand) | & |
| " (double quote) | " |
| ' (single quote) | ' |
| < (less than) | < |
| > (greater than) | > |
The function htmlspecialchars is located in the file xml.jsxinc.
Usage
To get the converted string:
var text = 'John wrote "1 < 2" on the blackboard.'; var escaped = htmlspecialchars(text);
Parameters
| Parameter | Data type | Required | Description |
|---|---|---|---|
| string | String | ![]() |
The string to be escaped. |
Return values
| Value | Meaning |
|---|---|
| string | The escaped string. |

