escaping - Unescape apostrophe (') in JavaScript? -


i'm trying unescape html-escaped apostrophe ("'") in javascript, following doesn't seem work on devtools console line:

unescape('''); 

the output simply:

"'" 

it doesn't work in underscore's unescape either:

_.unescape(''') 

what doing wrong?

unescape has nothing html character entities. it's old, deprecated function decoding text encoded escape, old, deprecated function encoding text in way unlikely useful in modern world. :-)

if need turn html plain text, easiest way via element:

var div = document.createelement('div'); div.innerhtml = "'"; alert(div.firstchild.nodevalue); 

live example | live source

note above relies on fact there no elements defined in html text, knows there 1 child node of div, text node.

for more complicated use cases, might use div.innertext (if has one) or div.textcontent:

var div = document.createelement('div'); div.innerhtml = "'"; alert(div.innertext || div.textcontent || ""); 

live example | live source


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -