Global.escape()

JavaScript 1.0+, ECMAScript 1.0+, JScript 1.0+ Nav2+, NES2+, IE 3+, 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.133 shows how to use the escape() method and what it returns. It takes a string of text and returns the escaped value.

Listing 6.133 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 ...

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.