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

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -