Is it possible to convert html tags to html entities using javascript/jquery using any way possible such as regex or some other way. If yes, then how?
Exampl
I have 2 fast and small implementations for encoding HTML safely.
You can encode all characters in your string:
function encode(e){return e.replace(/[^]/g,function(e){return""+e.charCodeAt(0)+";"})}
Or just target the main characters to worry about (&, inebreaks, <, >, " and ') like:
function encode(r){
return r.replace(/[\x26\x0A\<>'"]/g,function(r){return""+r.charCodeAt(0)+";"})
}
var myString='Encode HTML entities!\n"Safe" escape