Started

Selectors

Utilities

Animation

AJAX

CSS

Event

Manipulation

Cookie

String

Attributes

Data

Storage

Miscellaneous

$string.replace

Replace multi-text within a portion of a string.
$string( string, replacements )
  1. string [string]
    The target string.
  2. replacements [object]
    The object containing needle as name and replacement as value.

Notes

This function is useful for replacing multi-characters.

Example

HTML code
<div id="box">&lt;div&gt;Hi, world!&lt;/div&gt;</div>
<button onclick="start_string_replace()">Start replace</button>
CSS code
#box {
	width: 200px;
	height: 60px;
	font-size: 12px;
	background: #5599bb;
	padding: 10px;
}
JavaScript code
function html_filter(string)
{
    return $string.replace(string, {
        '&': '&amp;',
        '"': '&quot;',
        "'": '&#039;',
        '<': '&lt;',
        '>': '&gt;',
        "\t": '&nbsp;&nbsp;',
        "\n": '<br />'
    });
}
function start_string_replace()
{
	alert(html_filter($html($("box"))));
}
Demonstration
<div>Hi, world!</div>