Replaces each markup-significant character in a string with its corresponding character entity.
JSV_toCharacterEntity(expS)
expS.toCharacterEntity()
Returns the string expS, with every occurrence of the markup-significant characters replaced by its corresponding character entity.
The toCharacterEntity function uses the following arguments.
Argument | Description |
expS | The string that is to be converted. |
The markup-significant characters and their corresponding character entity are:
Markup-Significant Character |
Character Entity | |
---|---|---|
& | & | |
< | < | |
> | > | |
" | " |
See the Web Design Group HTML 4.0 Reference on Special Entities for more information.
If you should modify the function to include more of the markup-significant characters, be sure that & is the first markup-significant character to be replaced. Note that the list of strings to be replaced is processed one after another. In this way you may experience recursive replacement if one of the latter elements is contained in any of the earlier elements. For example, you may end up replacing the & in the other markup-significant characters (e.g., >) if & is placed latter in the list rather than first.
The following lines of code
var myString =
'Everyone should visit ' +
'<A HREF="http://www.irt.org/index.htm">irt.org</A> ' +
'at least once in their life.';
document.write( JSV_toCharacterEntity(myString) );
produce
The string myString is: |
Copyright © 1998-2000 Roaring Fork Software. All rights reserved.