escape()

JavaScript 1.0+, ECMAScript 1.0+, JScript 3.0+ NES2+, Nav2+, IE 4+, Opera3+ Syntax

escape(string)
escape(expression)

Description

The escape() method takes any string object or expression and returns a string object in which all non-alphanumeric characters are converted to their numeric equivalent in the form % XX. The XX is a hexadecimal number representing the non-alphanumeric character.

Example

Listing 6.117 shows how to use the escape() method. It takes a string of text and returns the escaped value.

Listing 6.117 Example of How to Use escape()
<script lanuguage="JavaScript">
var newString = escape("Tom & Jerry Show");
</script>

This returns: "Tom%20%26%20Jerry%20show". Notice that the spaces were replaced with "%20" ...

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.