Tuesday, 27 September 2011

Replace all angle brackets into its equavalent html codes in JavaScript


function ReplaceAngleBracketsToHtmlCode(strInput)
{   
   strInput = strInput.replace(new RegExp(['<'],"g"), "&lt;");
   strInput = strInput.replace(new RegExp(['>'],"g"), "&gt;");
  
   return strInput;  
}

alert(ReplaceAngleBracketsToHtmlCode("<Ravi>"));

Output:
&lt;Ravi&gt;

1 comment: