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);
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 || "");
Comments
Post a Comment