Elementals.js

Latest Version: 3.4 PRODUCTION 18 November 2017

Method String.htmlSpecialChars

Summary:

Escapes key characters in the string to make it safe to insert into HTML.

Calling Convention:
String.htmlSpecialChars()
Parameters
None
Returns:
The string with the greater than, less than, ampersand, single and double quotes escaped to their HTML entity equivalents.

Examples

HTML

var test = '<p>Test & "the Best"</p<';
console.log(test.htmlSpecialChars());

Output

&lt;p&gt;Test &amp; &quot;the Best&quote;&lt;/p&gt;

Advertisement